rubocop / rubocop/ruby-style-guide
New exception classes
Nobody has claimed this yet.
- Dominant language
- No language data
- Stars
- 16.5k
- Forks
- 3.3k
- PR merge metrics
- No merged PRs in 30d
Description
Prefer the use of exceptions from the standard library over introducing new exception classes.
I feel this is not quite accurate.
Indeed, a gem should use standard library exceptions in case the gem is called with invalid inputs (e.g. TypeError if called with an Integer instead of a String, ArgumentError, IndexError, etc.). Typically these are never rescued.
But when something proper to the gem happens, instead of raising a RuntimeError it should have its own subclasses of StandardError for that gem (with potentially a base class for the gem). E.g. ::Parser::SyntaxError, ::Parser::ClobberingError. Typically these may be rescued by the dependents of the gem.
May I amend the guide?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Search the style guide for the quoted recommendation to prefer standard-library exceptions. Read the surrounding guidance and the issue’s distinction between invalid inputs and gem-specific failures, then determine whether the wording should be amended. Done means the guide clearly reflects that distinction and the rendered documentation remains consistent.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100