Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose original error object in promises (or callbacks) #4

Closed
mhart opened this issue Dec 5, 2012 · 7 comments
Closed

Expose original error object in promises (or callbacks) #4

mhart opened this issue Dec 5, 2012 · 7 comments
Labels
guidance Question that needs advice or information.
Milestone

Comments

@mhart
Copy link
Contributor

mhart commented Dec 5, 2012

The current error structure in the promises implementation only supports a very simple message, so for situations where an error is thrown from the node.js stack for example, the error is converted into a string and all stack information etc is lost:

callbacks.onError({ code: 'NetworkingError', message: e.toString() });

It would be nice if the original error object could be added to the error structure so that it can be inspected, etc.

Edit: if node.js-style callbacks are going to be used (fingers crossed), then there shouldn't be any need for this error structure at all - just use/expose JS errors/exceptions.

@lsegal
Copy link
Contributor

lsegal commented Dec 5, 2012

Thanks. Clobbering the stack trace is a bug, IMO.

@trevorrowe
Copy link
Member

Fixed in 146b643 and released with 0.9.1-pre.2.

@mhart
Copy link
Contributor Author

mhart commented Dec 13, 2012

I think this may have been closed a bit summarily. The code is still littered with usages of this custom {code: '', message: ''} structure and strings instead of real JavaScript exceptions (which makes it very hard to deal with errors when they arise - are they JavaScript Error objects, are they some custom object, are they strings, etc).

Perhaps you want to extend the JS Error object and create your own AwsError or similar: http://www.devthought.com/2011/12/22/a-string-is-not-an-error/

Some examples:

throw { code: 'AWS.XML.Parser.Error', message: error.message };

throw { code: 'AWS.XML.Parser.Error', message: msg };

throw 'unhandled timestamp format: ' + value;




return {

@trevorrowe
Copy link
Member

There is a strong pattern across AWS services where the services may respond to a request with an error "code" and "message". The code is always a short string and the message is a longer description, often with details. When I call the EC2 DescribeInstances operation I might get an error back (in XML) that has the following attributes:

  • code: InvalidInstanceID.NotFound
  • message: "The instance ID 'i-12345678' does not exist"

The original intent was to limit the number of attributes a user needed to check on errors returned by the SDK. If errors generated by the SDK (or its dependency) mimicked those returned by the services then error handling could be generalized to a point.

That said, I see the issue where these object do not generate stack traces and can actually make error handling more difficult. At this point, I think standardizing on An error class (like AWS.Error) that extends Error makes good sense.

@trevorrowe trevorrowe reopened this Dec 13, 2012
@lsegal
Copy link
Contributor

lsegal commented Dec 13, 2012

I'm prototyping something based on AWS.Error right now, FYI.

lsegal added a commit that referenced this issue Dec 13, 2012
Add AWS.util.error() to wrap an Error object with extra properties:

* code: a unique shorthand code for a service error
* statusCode: the HTTP status code of an errant request (if service error)
* retryable: whether the request that raised this error should be retried

References #4
@lsegal
Copy link
Contributor

lsegal commented Dec 13, 2012

See the node-errors branch for the code.

@lsegal lsegal closed this as completed in 395041e Dec 16, 2012
@srchase srchase added guidance Question that needs advice or information. and removed Question labels Jan 4, 2019
@lock
Copy link

lock bot commented Sep 29, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@lock lock bot locked as resolved and limited conversation to collaborators Sep 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
guidance Question that needs advice or information.
Projects
None yet
Development

No branches or pull requests

4 participants