Skip to content

Commit

Permalink
- Catch DocoptLanguageError and reraise Runfile::SyntaxError
Browse files Browse the repository at this point in the history
  • Loading branch information
DannyBen committed Jan 28, 2023
1 parent eb32080 commit 651bd5d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/runfile/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def run(args = {})

instance_eval do
host.helpers.each { |b| b.call args }
block.call args
block.call args if block
end
end

Expand Down
1 change: 1 addition & 0 deletions lib/runfile/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ class ExitWithUsage < Error; end
class ActionNotFound < UserError; end
class GemNotFound < UserError; end
class SyntaxError < UserError; end
class DocoptError < SyntaxError; end
end
2 changes: 2 additions & 0 deletions lib/runfile/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def call_docopt(docopt, version: nil, argv: nil)
Docopt.docopt docopt, argv: argv, version: version
rescue Docopt::Exit => e
raise ExitWithUsage, e.message
rescue Docopt::DocoptLanguageError => e
raise DocoptError, "There is an error in your runfile:\nnb`#{e.message}`"
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions spec/approvals/runner/docopt-error
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#<Runfile::DocoptError: There is an error in your runfile:
nb`unmatched '['`>
16 changes: 16 additions & 0 deletions spec/runfile/runner_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
describe Runner do
subject { described_class }

let(:docopt) do
<<~DOCOPT
Usage:
backup [PATH --force#{' '}
DOCOPT
end

describe '#run' do
it 'raises Runfile::SyntaxError on docopt error' do
expect { subject.run docopt }.to raise_approval('runner/docopt-error')
end
end
end

0 comments on commit 651bd5d

Please sign in to comment.