# please remove the error types

**URL:** <https://es.discourse.group/t/please-remove-the-error-types/2357>\
**Category:** 💡 Ideas\
**Created:** [April 23, 2025, 7:34pm UTC](https://es.discourse.group/t/please-remove-the-error-types/2357 "2025-04-23T19:34:04Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![YeesterPlus](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/yeesterplus/32/2520_2.png) [@YeesterPlus](https://es.discourse.group/u/YeesterPlus)\
**Post date:** [April 23, 2025, 7:34pm UTC](https://es.discourse.group/t/please-remove-the-error-types/2357/1 "2025-04-23T19:34:05Z")

</div>

error.name leads to disasters with readability because, it lets programmers get away with unreadability.

```javascript
//no fix
try{
    ['a'].forEach('a')
}catch(err){console.log(err.name)} //"TypeError" (duplicate info)
//with fix
try{
['a'].forEach('a')
}catch(err){console.log(err.name)} //undefined

```

---

<div class="post-metadata">

**Author:** ![swhiteman](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/swhiteman/32/716_2.png) [@swhiteman](https://es.discourse.group/u/swhiteman)\
**Post date:** [April 23, 2025, 8:55pm UTC](https://es.discourse.group/t/please-remove-the-error-types/2357/2 "2025-04-23T20:55:49Z")

</div>

Hi,

Not getting what you mean by 'get away with' here. What's the readability aspect? Why is the ability to check `name` increasing unreadability?

Also bear in mind `name` and the error class name do not always have the same value, e.g. when you subclass `Error` and don't deliberately set `name`.

(Vanishingly unlikely that the `name` property would be removed for built-in error classes, unless there were a security implication.)

---

<div class="post-metadata">

**Author:** ![YeesterPlus](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/yeesterplus/32/2520_2.png) [@YeesterPlus](https://es.discourse.group/u/YeesterPlus)\
**Post date:** [April 24, 2025, 12:13am UTC](https://es.discourse.group/t/please-remove-the-error-types/2357/3 "2025-04-24T00:13:24Z")

</div>

replace the error name with a property called Error.info to where you get parseable information about the error

---

<div class="post-metadata">

**Author:** ![YeesterPlus](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/yeesterplus/32/2520_2.png) [@YeesterPlus](https://es.discourse.group/u/YeesterPlus)\
**Post date:** [April 24, 2025, 12:19am UTC](https://es.discourse.group/t/please-remove-the-error-types/2357/4 "2025-04-24T00:19:30Z")

</div>

```javascript
try {
  ['a'].forEach('a')
}catch(err){ 
  console.log(JSON.stringify(err.info))/*{
   value:"a",
   type:"string",
   supposedType:"function"
 }*/
}

```

---

<div class="post-metadata">

**Author:** ![swhiteman](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/swhiteman/32/716_2.png) [@swhiteman](https://es.discourse.group/u/swhiteman)\
**Post date:** [April 24, 2025, 12:55am UTC](https://es.discourse.group/t/please-remove-the-error-types/2357/5 "2025-04-24T00:55:46Z")

</div>

OK, see what you're driving at here. Though unsure where the conventional meaning of code readability comes in.

Either way I don't see it as likely that someone would work with these kinds of structured `Error.info` objects as-is. Seems to me they'd end up being sprintf'd in reality, which is what `Error.prototype.toString()` already does. The JS object is _somewhat_ readable, but surely not as easy to follow as the message constructed by the engine.

Can you nominate some other languages where the individual components of an error - the args passed to sprintf, basically - are available in userland? I guess if the app you're building is specifically a debugger/analysis app, i.e. analyzing 3rd party code, it could be useful to see how frequently a certain type mismatch happened.

Further reading: [GitHub - tc39/proposal-error-capturestacktrace: Standardizing Error.captureStackTrace](https://github.com/tc39/proposal-error-capturestacktrace?tab=readme-ov-file#errorcapturestacktrace-1)

---

<div class="post-metadata">

**Author:** ![ljharb](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ljharb/32/8_2.png) [@ljharb](https://es.discourse.group/u/ljharb)\
**Post date:** [April 24, 2025, 12:57am UTC](https://es.discourse.group/t/please-remove-the-error-types/2357/6 "2025-04-24T00:57:13Z")

</div>

You're free to make an Error that has that information, but not all exception scenarios _can_ provide data like that.

Either way, `.name` can literally never be removed, because it would break the web.

---

<div class="post-metadata">

**Author:** ![YeesterPlus](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/yeesterplus/32/2520_2.png) [@YeesterPlus](https://es.discourse.group/u/YeesterPlus)\
**Post date:** [April 24, 2025, 1:00am UTC](https://es.discourse.group/t/please-remove-the-error-types/2357/7 "2025-04-24T01:00:52Z")

</div>

change it to .constructor.name and hide it from code using the stringified version and the console

---

<div class="post-metadata">

**Author:** ![YeesterPlus](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/yeesterplus/32/2520_2.png) [@YeesterPlus](https://es.discourse.group/u/YeesterPlus)\
**Post date:** [April 24, 2025, 1:03am UTC](https://es.discourse.group/t/please-remove-the-error-types/2357/8 "2025-04-24T01:03:09Z")

</div>

the engine might need some fixing, plus Error.info could be pretty useful for handling errors because, it will basically be `.message` but for code instead of the user

---

<div class="post-metadata">

**Author:** ![ljharb](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ljharb/32/8_2.png) [@ljharb](https://es.discourse.group/u/ljharb)\
**Post date:** [April 24, 2025, 1:12am UTC](https://es.discourse.group/t/please-remove-the-error-types/2357/9 "2025-04-24T01:12:02Z")

</div>

It can't be changed, EVER, or existing code would break.

---

<div class="post-metadata">

**Author:** ![YeesterPlus](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/yeesterplus/32/2520_2.png) [@YeesterPlus](https://es.discourse.group/u/YeesterPlus)\
**Post date:** [April 24, 2025, 1:13am UTC](https://es.discourse.group/t/please-remove-the-error-types/2357/10 "2025-04-24T01:13:57Z")

</div>

make `err.name` be the same as `err.info.errorName||err.constructor.name`  
and `err.name=` be the same as `err.info.errorName=`.  
Also plz deprecate `.error` but, never remove it

---

<div class="post-metadata">

**Author:** ![ljharb](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ljharb/32/8_2.png) [@ljharb](https://es.discourse.group/u/ljharb)\
**Post date:** [April 24, 2025, 1:25am UTC](https://es.discourse.group/t/please-remove-the-error-types/2357/11 "2025-04-24T01:25:35Z")

</div>

Why would that solve the problem you mentioned at the beginning? Surely everyone will reach for the reliably present `.name` instead of something deeply under `.info`.

---

<div class="post-metadata">

**Author:** ![YeesterPlus](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/yeesterplus/32/2520_2.png) [@YeesterPlus](https://es.discourse.group/u/YeesterPlus)\
**Post date:** [April 24, 2025, 1:27am UTC](https://es.discourse.group/t/please-remove-the-error-types/2357/12 "2025-04-24T01:27:21Z")

</div>

make `.name` get the value under `.info.errorName` when accessed, plus `.info.errorName` might not be present so, if its not there, just use the class name for the value until `.name` or `.info.errorName` is set

---

<div class="post-metadata">

**Author:** ![ljharb](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ljharb/32/8_2.png) [@ljharb](https://es.discourse.group/u/ljharb)\
**Post date:** [April 24, 2025, 1:42am UTC](https://es.discourse.group/t/please-remove-the-error-types/2357/13 "2025-04-24T01:42:18Z")

</div>

I'm not asking how to technically achieve it - there's lots of ways.

I'm asking how that solves your actual problem. Perhaps it would help if you restated the problem without talking about a potential solution?

---

<div class="post-metadata">

**Author:** ![YeesterPlus](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/yeesterplus/32/2520_2.png) [@YeesterPlus](https://es.discourse.group/u/YeesterPlus)\
**Post date:** [April 24, 2025, 1:45am UTC](https://es.discourse.group/t/please-remove-the-error-types/2357/14 "2025-04-24T01:45:53Z")

</div>

error types seem unnecessary for people if the message conveys whats wrong

---

<div class="post-metadata">

**Author:** ![juner](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/juner/32/2377_2.png) [@juner](https://es.discourse.group/u/juner)\
**Post date:** [April 24, 2025, 2:00am UTC](https://es.discourse.group/t/please-remove-the-error-types/2357/15 "2025-04-24T02:00:21Z")

</div>

Wouldn't it be better to add the additional information to `.cause`?

[Proposal: Enhanced Network Error Handling Using Error.cause - 💡 Ideas - TC39](https://es.discourse.group/t/proposal-enhanced-network-error-handling-using-error-cause/2329)

---

<div class="post-metadata">

**Author:** ![YeesterPlus](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/yeesterplus/32/2520_2.png) [@YeesterPlus](https://es.discourse.group/u/YeesterPlus)\
**Post date:** [April 24, 2025, 2:10am UTC](https://es.discourse.group/t/please-remove-the-error-types/2357/16 "2025-04-24T02:10:37Z")

</div>

yes

---

<div class="post-metadata">

**Author:** ![theScottyJam](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/thescottyjam/32/616_2.png) [@theScottyJam](https://es.discourse.group/u/theScottyJam)\
**Post date:** [April 25, 2025, 6:10pm UTC](https://es.discourse.group/t/please-remove-the-error-types/2357/17 "2025-04-25T18:10:58Z")

</div>

> error types seem unnecessary for people if the message conveys whats wrong

Is this specifically an issue with the "name" property, or do you dislike the idea of having different error types in general? Assuming it's the latter...

The usefulness depends on the nature of the error.

For example, if I'm using Node and am trying to open a file, but the file does not exist, it's going to throw a very specific error that I can catch and programmatically handle. In Node's case they choose to attach a "code" property to the error for me to inspect, but they could have subclasses ”Error" as well, and then I would check if the error thrown is of the type FileNotFound. Either way, I don't want my code trying to inspect the error message to figure out if it was a file not found error or something else - that's very unreliable, I need some kind of error type to check.

---

<div class="post-metadata">

**Author:** ![YeesterPlus](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/yeesterplus/32/2520_2.png) [@YeesterPlus](https://es.discourse.group/u/YeesterPlus)\
**Post date:** [April 28, 2025, 8:28pm UTC](https://es.discourse.group/t/please-remove-the-error-types/2357/18 "2025-04-28T20:28:14Z")

</div>

only code and programmers should be able to read it, not users using inspect element

---

<div class="post-metadata">

**Author:** ![ljharb](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ljharb/32/8_2.png) [@ljharb](https://es.discourse.group/u/ljharb)\
**Post date:** [April 28, 2025, 8:51pm UTC](https://es.discourse.group/t/please-remove-the-error-types/2357/19 "2025-04-28T20:51:42Z")

</div>

That's not really viable; it's a web principle that the user of a browser is in control.

---

<div class="post-metadata">

**Author:** ![theScottyJam](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/thescottyjam/32/616_2.png) [@theScottyJam](https://es.discourse.group/u/theScottyJam)\
**Post date:** [April 28, 2025, 10:22pm UTC](https://es.discourse.group/t/please-remove-the-error-types/2357/20 "2025-04-28T22:22:21Z")

</div>

"inspect element" is a tool designed for programmers, so if programmers are allowed to see it, it makes sense to show it in the dev tools console. In fact, it's very important that the error type is displayed there - for APIs that aren't documented very well, seeing the error type in the console is an invaluable way for the programmer to learn how to adjust their code to catch that error type.

The end user using the webpage normally (not using dev tools) shouldn't need to see that error code (except, perhaps to report that information in a bug report). But that's on the webpage author to omit that information when displaying errors to the end user.

[Next page](https://es.discourse.group/t/please-remove-the-error-types/2357.md?page=2)
