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 ;)
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.
@clintwood
Thanks for opening the rollup issue.
I opened a Node issue too.
v0.11.1 is released 馃帀
Fixed in Node https://github.com/nodejs/node/commit/42a2a9badb6974e47b98aaee052e9710f34b93e8 too :tada:
Most helpful comment
v0.11.1 is released 馃帀