sindresorhus/serialize-error

Add option to decide behavior

Open

#25 geöffnet am 23. Sept. 2019

Auf GitHub ansehen
 (5 Kommentare) (2 Reaktionen) (0 zugewiesene Personen)JavaScript (69 Forks)user submission
enhancementhelp wanted

Repository-Metriken

Stars
 (599 Stars)
PR-Merge-Metriken
 (Keine gemergten PRs in 30 T)

Beschreibung

You can throw anything in JS, but it's a bad practice. I'd like to have it fail rather than silently accept anything. Though, it's not a good default, so should be opt-in.

Actually, there's 3 possible behaviors:

  1. Always return an object. (wanted default)
  2. Passthrough non-object values. (current default)
  3. Throw on non-object input.

I'd like 1 to be the default behavior, for consistency, but add an option to be able to opt into 2 (which is the current behavior) or 3 (which would be the strict behavior). This should be a single option.

Another benefit of 1 is that the TypeScript types can be better. We can guarantee it's an object and we can also guarantee that the name, message, and stack properties exist.

Contributor Guide