Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Should Error.code be readonly? #113

Closed
clintwood opened this issue Sep 28, 2017 · 4 comments
Closed

Should Error.code be readonly? #113

clintwood opened this issue Sep 28, 2017 · 4 comments
Labels

Comments

@clintwood
Copy link

I'm using Rollup which modifies the code property on a caught Error object to augment Error.code for their specific context.

In @std/esm Error.code is defined as a getter so when rollup tries to 'augment' the error by setting code I get an error thrown by rollup, TypeError: Cannot set property code of [object Object] which has only a getter, which is wholly misleading.

I noticed that if you create a standard Error object in Node there is no code property by default and one is free to add or modify it at will.

So code should probably be a writable prop so that libraries like Rollup can 'augment' errors to be more specific for their unique contexts! This case may not be unique to Rollup as other libraries may do the same!

PS I couldn't find any specs on the how an Error object should behave - but didn't look too hard ;)

@jdalton
Copy link
Member

jdalton commented Sep 28, 2017

Hi @clintwood!

We're following Node's behavior here. See internal/errors. Node is starting to increase usage of its internal/errors class throughout its code base. It looks like an oversight on Node's part since folks are modifying the code property in the wild. It's easy enough for use to tweak on our end. You might give rollup a heads up though.

@jdalton
Copy link
Member

jdalton commented Sep 28, 2017

@clintwood

Thanks for opening the rollup issue.
I opened a Node issue too.

@jdalton
Copy link
Member

jdalton commented Sep 29, 2017

v0.11.1 is released 🎉

@jdalton
Copy link
Member

jdalton commented Oct 5, 2017

Fixed in Node nodejs/node@42a2a9b too 🎉

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

No branches or pull requests

2 participants