-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[WIP] feat: add errors with codes and utils #1746
Conversation
I really like to have better errors. When we roll out proper errors, we might want to consider adding a You can use And as I stumbled upon another great read recently, I'll also put that one out here: http://250bpm.com/blog:140 |
Big +1 on this, if follows Node core approach. Note that in readable-stream we had to do a custom porting of the logic to support old browsers. I think it's preferrable to not use a map and just use an object. Docs for the error codes are missing. |
I also agree with moving on with this approach for the errors. My biggest concern is that with so many modules, I don't think that the best approach is to have errors defined in all those modules and export them so that they can be used by the others. At least, we should have the more generic errors in their own module. |
I like this. We do need to deal with the case where we get an error from a dependency and want to "wrap it" to preserve the original (as @vmx noted). This proposal doesn't allow us to do that right now but @vmx - my concern with adding a Chrome (cannot see
|
I am totally on this |
That would be cool |
I'm more concerned about having the information be stored somewhere. When you use a debugger, you can still access it. If we can make it even show up in the Browser console that would be even better. |
Another things I came across while working on some code. Let's assume you delete several items by CID, but that's not always successful, so you might get an error message. You would want to know on which CID it failed. You can add this information to the error message text, but you won't have programmatic access to it. So what about changing the Example: // Instead of
new ERR_IPFS_MISSING_IPLD_FORMAT(codec)
// You would do
new ERR_IPFS_MISSING_IPLD_FORMAT({ codec: codec })
// Or if you're fancy
new ERR_IPFS_MISSING_IPLD_FORMAT({ codec }) The format string would be: // Instead of
'Missing IPLD format %s'
// You'd be using
`Missing IPLD format ${args.codec}` The advantage would be that the error object itself could have a field called e.g. |
Is there a plan to continue with this? I think that there is a big improvement space for error handling in I would also suggest having a one master table where all error codes would be collected from all |
@hugomrdias do you plan to move forwards with this or shall we close? |
i plan to include this in this quarter work |
Closing as stale |
This PR adds a proposal to improve the error handling beyond using
err-code
, with these changes we create static errors backed by error classes and printf style formatted messages.This approach is a simplified version of node's errors https://github.com/nodejs/node/blob/master/lib/internal/errors.js, i guess if it's good for node's code base it should also be good for us.
The benefits :
err.code === ERR_IPFS_MISSING_IPLD_FORMAT.code
Please give feedback about this PR if we all agreed with this i'll change the rest of code to this pattern. //cc @ipfs/javascript-team