Skip to content
This repository has been archived by the owner on Mar 31, 2018. It is now read-only.

Examples of synchronous operational errors #23

Closed
benjamingr opened this issue Feb 16, 2016 · 4 comments
Closed

Examples of synchronous operational errors #23

benjamingr opened this issue Feb 16, 2016 · 4 comments

Comments

@benjamingr
Copy link
Member

I'd like to collect some examples of operational errors in Node that are synchronously thrown at the moment.

Please post examples you're aware of

Examples:

  1. Out of memory
  2. Parsing invalid JSON
  3. Attempting to bind to a closed UDP socket.
  4. Listening to an invalid port

Out of memory

const arr = []; // example and case by trevnorris
  while (true)
    arr.push(new Buffer(0xfffffff).fill(0));  // alloc until OOM, throws synchronously

Parsing Invalid JSON

var j = JSON.parse("{'hello': 5}"); // throws synchronously

Attempting to bind to a closed UDP socket

From https://nodejs.org/api/dgram.html

If binding fails, an 'error' event is generated. In rare case (e.g. attempting to bind with a closed socket), an Error may be thrown.

Listening to an invalid port

https:/nodejs/node/blob/master/lib/net.js#L1340


Of course, every single *Sync method in the API throws synchronously, although in theory they could take callbacks and execute them with err synchronously. This includes calls to require for example.

@benjamingr
Copy link
Member Author

Related discussion: #10

@petkaantonov
Copy link
Contributor

I'd generalize that almost any error thrown in core can be operational depending on context. So just search for throw and there you go.

@benjamingr
Copy link
Member Author

@petkaantonov care to share some examples?

@thefourtheye
Copy link

I found few such instances while working on nodejs/node#5251. I had to fix the tests as well because they were expecting errors synchronously.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants