Skip to content

Commit 651bd5d

Browse files
committed
- Catch DocoptLanguageError and reraise Runfile::SyntaxError
1 parent eb32080 commit 651bd5d

File tree

5 files changed

+22
-1
lines changed

5 files changed

+22
-1
lines changed

lib/runfile/action.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def run(args = {})
2626

2727
instance_eval do
2828
host.helpers.each { |b| b.call args }
29-
block.call args
29+
block.call args if block
3030
end
3131
end
3232

lib/runfile/exceptions.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ class ExitWithUsage < Error; end
1010
class ActionNotFound < UserError; end
1111
class GemNotFound < UserError; end
1212
class SyntaxError < UserError; end
13+
class DocoptError < SyntaxError; end
1314
end

lib/runfile/runner.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ def call_docopt(docopt, version: nil, argv: nil)
1414
Docopt.docopt docopt, argv: argv, version: version
1515
rescue Docopt::Exit => e
1616
raise ExitWithUsage, e.message
17+
rescue Docopt::DocoptLanguageError => e
18+
raise DocoptError, "There is an error in your runfile:\nnb`#{e.message}`"
1719
end
1820
end
1921
end

spec/approvals/runner/docopt-error

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#<Runfile::DocoptError: There is an error in your runfile:
2+
nb`unmatched '['`>

spec/runfile/runner_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
describe Runner do
2+
subject { described_class }
3+
4+
let(:docopt) do
5+
<<~DOCOPT
6+
Usage:
7+
backup [PATH --force#{' '}
8+
DOCOPT
9+
end
10+
11+
describe '#run' do
12+
it 'raises Runfile::SyntaxError on docopt error' do
13+
expect { subject.run docopt }.to raise_approval('runner/docopt-error')
14+
end
15+
end
16+
end

0 commit comments

Comments
 (0)