Skip to content

Commit

Permalink
Rework error reporting, and fix pretty print of SPEC parse error
Browse files Browse the repository at this point in the history
  • Loading branch information
ysbaddaden committed Oct 6, 2017
1 parent fac0417 commit ee4087f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/errors.cr
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ module Shards
end

def to_s(io)
io.puts "in #{ filename }:#{ line_number }: #{ self.class.name }: #{ message }"
io.puts "in #{ filename }: #{ message }"
io.puts

lines = input.split('\n')
from = line_number - 2
from = line_number - 3
from = 0 if from < 0

lines[from .. line_number].each_with_index do |line, i|
io.puts " #{ i + 1 }. #{ line }"
lines[from ... line_number].each_with_index do |line, i|
io.puts " #{ from + i + 1 }. #{ line }"
end

arrow = String.build do |s|
Expand Down
2 changes: 1 addition & 1 deletion src/lock.cr
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module Shards
dependencies << Dependency.new(pull)
end
else
pull.raise "no such attribute #{key} in lock version 1.0"
pull.raise "No such attribute #{key} in lock version 1.0"
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions src/resolvers/git.cr
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ module Shards

private def run(command, path = local_path, capture = false)
unless GitResolver.has_git_command?
raise Error.new("Error: missing git command line tool. Please install Git first!")
raise Error.new("Error missing git command line tool. Please install Git first!")
end

# Shards.logger.debug { "cd #{path}" }
Expand All @@ -233,7 +233,7 @@ module Shards
if str.starts_with?("error: ") && (idx = str.index('\n'))
message = str[7 ... idx]
end
raise Error.new("git command failed: #{ command } (#{ message }). Maybe a commit, branch or file doesn't exist?")
raise Error.new("Failed #{ command } (#{ message }). Maybe a commit, branch or file doesn't exist?")
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/resolvers/resolver.cr
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ module Shards
def self.find_resolver(dependency, update_cache = true)
@@resolvers[dependency.name] ||= begin
klass = get_resolver_class(dependency.keys)
raise Error.new("can't resolve dependency #{dependency.name} (unsupported resolver)") unless klass
raise Error.new("Failed can't resolve dependency #{dependency.name} (unsupported resolver)") unless klass
klass.new(dependency, update_cache: update_cache)
end
end
Expand Down
14 changes: 9 additions & 5 deletions src/spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ module Shards

def self.new(pull : YAML::PullParser)
name = pull.read_scalar

line, column = pull.location
version = pull.read_scalar.strip if pull.kind.scalar?

if version && !version.empty?
new(name, version)
else
raise Error.new("library version of #{name} can't be empty, use * for any version.")
if !version || version.try(&.empty?)
pull.raise "library version for #{name} can't be empty, use * for any version", line, column
end

new(name, version)
end

def initialize(@soname, @version)
Expand Down Expand Up @@ -71,6 +73,8 @@ module Shards
# :nodoc:
def initialize(pull : YAML::PullParser, validate = false)
pull.each_in_mapping do
line, column = pull.location

case key = pull.read_scalar
when "name"
@name = pull.read_scalar
Expand Down Expand Up @@ -108,7 +112,7 @@ module Shards
end
else
if validate
pull.raise "unknown attribute: #{key}"
pull.raise "unknown attribute: #{key}", line, column
else
pull.skip
end
Expand Down

0 comments on commit ee4087f

Please sign in to comment.