Skip to content

Commit

Permalink
[DSLError] It should definitely be an Informative
Browse files Browse the repository at this point in the history
@alloy :-)
  • Loading branch information
fabiopelosin committed Sep 9, 2013
1 parent 9e592ef commit d7d3481
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ GIT

GIT
remote: https://github.com/irrationalfab/PrettyBacon.git
revision: 0da7e231bf597005aaa4efb4c2cd837336a6b42b
revision: 926c214ade1ec1cbc9544d603e36f15a780f7e68
branch: master
specs:
prettybacon (0.0.1)
Expand Down
3 changes: 1 addition & 2 deletions lib/cocoapods-core/specification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,7 @@ def self._eval_podspec(string, path)
begin
eval(string, nil, path.to_s)
rescue Exception => e
raise DSLError.new("Invalid `#{path.basename}` file: #{e.message}",
path, e.backtrace)
raise DSLError.new("Invalid `#{path.basename}` file: #{e.message}", path, e.backtrace)
end
end
end
13 changes: 8 additions & 5 deletions lib/cocoapods-core/standard_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class StandardError < ::StandardError; end
# Wraps an exception raised by a DSL file in order to show to the user the
# contents of the line that raised the exception.
#
class DSLError < StandardError
class DSLError < Informative

# @return [String] the description that should be presented to the user.
#
Expand Down Expand Up @@ -53,11 +53,14 @@ def initialize(description, dsl_path, backtrace)
#
def message
unless @message
m = description.dup
m = "\n[!] "
m << description
m << ". Updating CocoaPods might fix the issue.\n"
m = m.red if m.respond_to?(:red)

return m unless backtrace && dsl_path && File.exist?(dsl_path)

trace_line = backtrace.find { |l| l =~ /#{dsl_path}/ }
trace_line = backtrace.find { |l| l.include?(dsl_path.to_s) }
return m unless trace_line
line_numer = trace_line.split(':')[1].to_i - 1
return m unless line_numer
Expand All @@ -67,15 +70,15 @@ def message
first_line = ( line_numer.zero? )
last_line = ( line_numer == (lines.count - 1) )

m << "\n #\n"
m << "\n"
m << "#{indent}from #{trace_line.gsub(/:in.*$/,'')}\n"
m << "#{indent}-------------------------------------------\n"
m << "#{indent}#{ lines[line_numer - 1] }" unless first_line
m << "#{indicator}#{ lines[line_numer] }"
m << "#{indent}#{ lines[line_numer + 1] }" unless last_line
m << "\n" unless m.end_with?("\n")
m << "#{indent}-------------------------------------------\n"
m << " #"
m << ""
@message = m
end
@message
Expand Down

1 comment on commit d7d3481

@alloy
Copy link
Member

@alloy alloy commented on d7d3481 Sep 10, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hahaha, good call. ❤️

Please sign in to comment.