question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

standard way to ignore an error

See original GitHub issue

This is mostly just a discussion item rather than a serious issue.

Currently standard uses handle-callback-err which complains if you do not “handle” callback errors.

Sometimes you do want to not handle an error e.g. ignore mkdirp errors.

The current rule is good as it encourages you to explicitly flag intentionally ignored errors rather than just leaving the future reader wondering whether the error was left ignored accidentally or for some purpose.

Even prior to using standard, I try to always flag explicitly ignored errors with a comment like so

mkdirp('/dir/might/exist', err => {
  // ignore error
  doStuff()
})

This only changed slightly upon starting to use standard:

mkdirp('/dir/might/exist', err => {
  err // ignore error 
})

try {
  mkdirp.sync('/dir/might/exist')
} catch (err) {
  err // ignore err
}

Another option could be to use a different variable name for ignored errors:

mkdirp('/dir/might/exist', ignoreErr => {
  doStuff()
})

Does anyone else have a standard pattern they use for flagging “ignored” errors?

It’s a possibility that even with the comment this is still a crappy workaround and I really should be explicitly whitelisting the error.code === 'EEXIST' case and throw err/return callback(err) otherwise.

Note that it’s also still valid to not add any comment, which makes it again unclear whether the error is being ignored intentionally or not:

mkdirp('/dir/might/exist', err => {
  err
  doStuff()
})

This should perhaps be disallowed.

In fact, I’m not sure there’s any valid reason for a statement to solely contain a reference to a variable like that since it’s a noop so perhaps I’m really requesting a rule for something like “no useless statements”.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
ferosscommented, Sep 14, 2016

Yeah, _ is a nice solution. That’s what I use. But this is a pretty rare occurrence.

1reaction
ferosscommented, Feb 9, 2017

Closing, since discussion has concluded 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python: How to ignore an exception and proceed? [duplicate]
The standard "nop" in Python is the pass statement: try: do_something() except Exception: pass. Using except Exception instead of a bare except avoid ......
Read more >
How to Ignore All the Errors in Excel (Explained) - Excel Champs
The best way to deal with errors is to use the IFERROR function. In this function, you have two arguments to define. The...
Read more >
How to Ignore All Errors in Microsoft Excel - groovyPost
The best way to stop error messages from appearing in Excel is to use the IFERROR function. IFERROR uses IF logic to check...
Read more >
Top 3 Ways To Handle or Ignore All Errors In MS Excel
Method 3# Hide error values and error indicators · Go to the Excel menu and tap the Preferences option. · Within the Formulas...
Read more >
Best way to ignore errors - MSDN - Microsoft
One approach is to use Publish to make the source hot and then return it as the new observable when OnError is called....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found