# Standardize \`error.code\`?

**URL:** <https://es.discourse.group/t/standardize-error-code/2490>\
**Category:** 💡 Ideas\
**Created:** [February 16, 2026, 3:16pm UTC](https://es.discourse.group/t/standardize-error-code/2490 "2026-02-16T15:16:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![LeaVerou](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/leaverou/32/1660_2.png) [@LeaVerou](https://es.discourse.group/u/LeaVerou)\
**Post date:** [February 16, 2026, 3:16pm UTC](https://es.discourse.group/t/standardize-error-code/2490/1 "2026-02-16T15:16:39Z")

</div>

When handling errors, a common need is to detect what type of error you have. Currently, the only ways per spec are quite suboptimal:

1. String matching on `error.message` , which is extremely fragile
2. Creating (often pointless) subclasses for every possible error, for the sole purpose of detection. Deno seems to follow that approach: [https://docs.deno.com/api/deno/\~/Deno.errors](https://docs.deno.com/api/deno/%5C~/Deno.errors) . That’s …a lot of subclasses.

NodeJS supports an [`error.code`](https://nodejs.org/api/errors.html#errorcode) property for specifying an error id (e.g. `"ENOENT”`) that is guaranteed to be more stable. It seems to be added ad hoc on `Error` instances (`"code” in Error.prototype` returns `false` ) and authors need to create their own abstractions if they want to use a similar mechanism, as there is no way to create an `Error` with a `code` through the `Error` constructor: passing `code` as an option is simply ignored. [Bun does this too](https://bun.com/docs/runtime/s3#error-codes).

I wonder if it would make sense to standardize a `code` option that could be passed to the `Error` constructor for specifying such stable codes, so it could be depended on, and available to authors without custom abstractions.

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/senocular/32/642_2.png) [@senocular](https://es.discourse.group/u/senocular)\
**Post date:** [February 16, 2026, 4:10pm UTC](https://es.discourse.group/t/standardize-error-code/2490/2 "2026-02-16T16:10:52Z")

</div>

This is on the [agenda for the upcoming March meeting](https://github.com/tc39/agendas/blob/def4abf007d5a84f8b9d1497bef69f0e589737ed/2026/03.md):

> **[GitHub - jasnell/proposal-error-code-property](https://github.com/jasnell/proposal-error-code-property)**
>
> Contribute to jasnell/proposal-error-code-property development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![bakkot](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/bakkot/32/22_2.png) [@bakkot](https://es.discourse.group/u/bakkot)\
**Post date:** [February 16, 2026, 4:40pm UTC](https://es.discourse.group/t/standardize-error-code/2490/3 "2026-02-16T16:40:51Z")

</div>

The proposal just allows user-created errors to define a `code`, rather than requiring specification-thrown errors to have a `code`.

Requiring specification-thrown errors to have a `code` would significantly constrain engines - many algorithms throw errors at multiple places with no user-observable code between them, which allows implementation strategies which do not distinguish between those types of errors; requiring a `code` would prevent them from doing this.

---

<div class="post-metadata">

**Author:** ![LeaVerou](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/leaverou/32/1660_2.png) [@LeaVerou](https://es.discourse.group/u/LeaVerou)\
**Post date:** [February 16, 2026, 5:32pm UTC](https://es.discourse.group/t/standardize-error-code/2490/4 "2026-02-16T17:32:54Z")

</div>

@senocular Wow, that’s some timing! Thank you for the pointer!

@bakkot What I was proposing was exactly what [GitHub - jasnell/proposal-error-code-property](https://github.com/jasnell/proposal-error-code-property) is proposing!

I _do_ think it would be a good idea generally for platform errors to have `error.code` once it’s available, but that should be a design principle, not a spec requirement (for a variety of reasons, one of which you mention).

Okay, I’ll go ahead and archive this then, since this is already a thing. Awesome!

---

<div class="post-metadata">

**Author:** ![LeaVerou](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/leaverou/32/1660_2.png) [@LeaVerou](https://es.discourse.group/u/LeaVerou)\
**Post date:** [February 16, 2026, 5:33pm UTC](https://es.discourse.group/t/standardize-error-code/2490/5 "2026-02-16T17:33:33Z")

</div>



---

<div class="post-metadata">

**Author:** ![LeaVerou](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/leaverou/32/1660_2.png) [@LeaVerou](https://es.discourse.group/u/LeaVerou)\
**Post date:** [February 16, 2026, 5:34pm UTC](https://es.discourse.group/t/standardize-error-code/2490/6 "2026-02-16T17:34:25Z")

</div>



---

<div class="post-metadata">

**Author:** ![LeaVerou](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/leaverou/32/1660_2.png) [@LeaVerou](https://es.discourse.group/u/LeaVerou)\
**Post date:** [February 16, 2026, 5:34pm UTC](https://es.discourse.group/t/standardize-error-code/2490/7 "2026-02-16T17:34:30Z")

</div>


