Esm: Should Error.code be readonly?

Created on 28 Sep 2017  路  4Comments  路  Source: standard-things/esm

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 ;)

bug

Most helpful comment

v0.11.1 is released 馃帀

All 4 comments

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 馃帀

Was this page helpful?
0 / 5 - 0 ratings

Related issues

StphamZ picture StphamZ  路  3Comments

dnalborczyk picture dnalborczyk  路  3Comments

tunnckoCore picture tunnckoCore  路  3Comments

greggb picture greggb  路  3Comments

Mensu picture Mensu  路  3Comments