Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nicer error message when activating nonexistent rule #246

Merged

Conversation

apjanke
Copy link
Contributor

@apjanke apjanke commented Dec 20, 2018

Currently, if I try to activate a non-existent rule in a style file, I get a hard-to-read stack trace error.

rule 'bogus-rule'
$ mdl _pages --style _linter/markdown-linter-style.rb                              ✘ 127 master ✱
Traceback (most recent call last):
	7: from /Users/janke/bin-local/mdl:23:in `<main>'
	6: from /Users/janke/bin-local/mdl:23:in `load'
	5: from /usr/local/lib/ruby/gems/2.5.0/gems/mdl-0.5.0/bin/mdl:10:in `<top (required)>'
	4: from /usr/local/lib/ruby/gems/2.5.0/gems/mdl-0.5.0/lib/mdl.rb:26:in `run'
	3: from /usr/local/lib/ruby/gems/2.5.0/gems/mdl-0.5.0/lib/mdl/style.rb:51:in `load'
	2: from /usr/local/lib/ruby/gems/2.5.0/gems/mdl-0.5.0/lib/mdl/style.rb:51:in `instance_eval'
	1: from _linter/markdown-linter-style.rb:4:in `load'
/usr/local/lib/ruby/gems/2.5.0/gems/mdl-0.5.0/lib/mdl/style.rb:30:in `rule': undefined method `params' for nil:NilClass (NoMethodError)

This PR adds an input check to produce a nicer error message when referencing a non-existent rule.

It also checks to see if rule was passed a block, which probably means that someone called the style rule DSL, when they meant to call the ruleset style DSL.

Would help with #244.

@apjanke apjanke force-pushed the nice-error-message-on-bogus-rule-reference branch from 78c3c33 to 504a3cb Compare December 20, 2018 07:38
@dgattey
Copy link

dgattey commented Feb 26, 2019

Nice - this is clean! Hope it gets merged

@jaymzh
Copy link
Member

jaymzh commented Oct 20, 2019

I pushed a commit to this branch do switch to unless and will merge.

@apjanke
Copy link
Contributor Author

apjanke commented Oct 20, 2019

👍

@jaymzh jaymzh merged commit 672496b into markdownlint:master Oct 20, 2019
@apjanke apjanke deleted the nice-error-message-on-bogus-rule-reference branch October 20, 2019 06:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants