-
Notifications
You must be signed in to change notification settings - Fork 370
Swallowing errors #327
Comments
There are a few minor issues with your statements but all in all, you are right as swagger-tools is not using json-refs properly. The first issue is that the json-refs used by swagger-tools is very old and has a few bugs, like not bubbling upstream errors properly. This was a result of json-refs trying to support callback and Promise based invocation. This is no longer the case in json-refs Upgrading json-refs would fix the issue. The second issue is that while So to summarize, we need to update json-refs in swagger-tools and use the Promise-based API properly to avoid this. |
I've figured this out. I bet your |
Except I get the exact same result locally without even specifying a NODE_ENV, or specifying NODE_ENV=production. The problem is you're trying to handle a swagger error, but this is a pure JavaScript stacktrace error that is simply being ignored within the quoted call as shown above. |
Then that is a json-refs issue. So there are two issues, both of which are described in this:
I'm on it. |
That doesn't cover my use-case entirely. Your solution is still to force exit my application, rather than letting userland code (i.e. mine) handle the error itself. What if I want to send the error over to a separate logging system first? Even if you did let the exception bubble up, I still couldn't even handle that within a |
That use case was never mentioned. I realize I don't mind supporting this but next time, how about we start with the "I would like to log the errors encountered in |
The biggest problem we'll run into with supporting this is that it breaks Let me think about this a little more. |
This will help some with #327 but it will not fix all of it.
Can you run your server with debugging on, For I'm just looking for a little more information so I fix this the right way. |
|
Thanks for the work on this @whitlockjc Unfortunately this became quite a blocker on our end, so I forked and made the changes necessary for us to see what was causing our crashes by passing the error back to magic, and then userland. confuser@a71e317 However, whilst this does the job and suits our needs, it gave a really bizarre path in terms of how errors are handled and is certainly not a correct solution/fix by any means. a127.init(function (error, config) {
if (error) return cb(error)
// Something that may throw here, e.g. throw new Error('Test')
}) In the above test case, one would normally expect the application to simply crash with a stack trace of the |
So, there are two places where errors can be thrown:
At runtime, all of this works fine because of the way the server works. An error thrown in a handler gets handled, etc. Where things are problematic are when you'er initializing the middleware typically: Invalid JavaScript in handlers, errors thrown in init, etc. The commit I made yesterday should fix this. While it does not return the error to user land so you can recover, it does log the error to the console prior to exiting the process. To fix this officially, I would need to make it so that |
https://github.com/apigee-127/swagger-tools/blob/master/index.js#L79-L89
Using
a127-magic
which depends on this module. Having a problem with any errors being thrown within it'sinit
function are silently being swallowed. This has made tracking down causes for crashes next to impossible, as the process simply silently exits.The above code is partly the cause, the fact that the error is only ever sent back within the callback under a
'test
environment, otherwise the process just exits without any mention oferr
.This is also incorrect behaviour as the default node callback styles are
callback(error, result)
, however `initializeMiddleware does not follow this standard pattern, which means that also will need to be changed.The other cause of this is
json-refs
not correctly passing back the error to the callback. I've raised a separate issue for this over at whitlockjc/json-refs#58 (comment) alongside a fixI will open a separate issue on https://github.com/apigee-127/magic with a request to use a correct node style callback.
The text was updated successfully, but these errors were encountered: