Closed
Bug 1437191
Opened 8 years ago
Closed 7 years ago
res.reportError should raise an exception
Categories
(Taskcluster :: Services, enhancement)
Taskcluster
Services
Tracking
(Not tracked)
RESOLVED
FIXED
People
(Reporter: dustin, Assigned: arshadkazmi42, Mentored)
References
Details
(Keywords: good-first-bug)
We currently rely on callers to return after calling `res.reportError`. We might as well enforce that by throwing an exception which tc-lib-api can then catch in the handler wrapper.
| Reporter | ||
Updated•8 years ago
|
Assignee: nobody → bstack
Updated•8 years ago
|
Flags: needinfo?(bstack)
| Reporter | ||
Updated•8 years ago
|
Mentor: dustin
Keywords: good-first-bug
Comment 3•8 years ago
|
||
:dustin I would like to take this up. Is this a mentored bug?
I would like some help getting started.
Flags: needinfo?(dustin)
| Reporter | ||
Comment 4•8 years ago
|
||
Sure! The reportError function is defined here:
https://github.com/taskcluster/taskcluster-lib-api/blob/master/src/middleware/errors.js
and the error-handling is here:
https://github.com/taskcluster/taskcluster-lib-api/blob/master/src/middleware/handle.js#L24
So the thing that is called at handle.js line 13 might call res.reportError, and might forget to return after the call. The fix is to throw an error in res.reportError, and then catch that error in handle.js and return gracefully.
Flags: needinfo?(dustin)
Comment 5•8 years ago
|
||
I am new to Java Script and this seems a bit unfamiliar. Can you provide some pointers as to how can i get started?
| Reporter | ||
Comment 6•8 years ago
|
||
One good way to approach something like this is to do test-driven-development: find the tests for the relevant bits and change them to represent the expected behavior. Then figure out why things break.
For example, this test
https://github.com/taskcluster/taskcluster-lib-api/blob/920a1094511dc73491e952202bd912d3d4decfb1/test/errors_test.js#L24
tests reportError. Try adding a line like `console.log('uhoh');` after the `res.reportError`, then run the tests and see that the console output is printed. The bug is to make that not happen :)
| Assignee | ||
Comment 7•7 years ago
|
||
Is this issue still open? I would like to work on this
Flags: needinfo?(dustin)
| Reporter | ||
Comment 8•7 years ago
|
||
Sure :)
BTW, you don't need to set the needinfo flag every time you comment in Bugzilla.
Assignee: nobody → arshadkazmi42
Flags: needinfo?(dustin)
| Assignee | ||
Comment 9•7 years ago
|
||
As per Comment 4
I tried adding throw
`throw {code, message, requestInfo};`
here
https://github.com/taskcluster/taskcluster-lib-api/blob/master/src/middleware/errors.js#L75
on this, it is going to this catch block.
https://github.com/taskcluster/taskcluster-lib-api/blob/master/src/middleware/handle.js#L29
Can you help me understand, how exactly we are planning to handle it in handle.js? Or even my throw state is at the correct place or not.
Flags: needinfo?(dustin)
| Reporter | ||
Comment 10•7 years ago
|
||
In handle.js, you'll want to do something similar to what is done in errors.js now -- res.status(..).json(). However, I see that handle.js is calling res.reportError as well. So you may need to do a small amount of refactoring to make that work -- I'll leave it to you to find a nice solution to that.
Flags: needinfo?(dustin)
| Assignee | ||
Comment 11•7 years ago
|
||
I did few changes.
Changed this line of code
https://github.com/taskcluster/taskcluster-lib-api/blob/master/src/middleware/errors.js#L75
to
`throw ({status, code, message, requestInfo});`
and changed this
https://github.com/taskcluster/taskcluster-lib-api/blob/master/src/middleware/handle.js#L34
to
`return res.status(err.status).json(err);`
The case mentioned in Comment 6 is done. The log after res.reportError is not getting logged in console.
But many of the other test cases are failing.
Is this fix correct, or there is something missing in this?
Flags: needinfo?(dustin)
| Reporter | ||
Comment 12•7 years ago
|
||
It sounds like it's not correct :)
For the next round, please file a pull request with your changes so that I can take a look.
Flags: needinfo?(dustin)
| Assignee | ||
Comment 13•7 years ago
|
||
I have created a PR here
https://github.com/taskcluster/taskcluster-lib-api/pull/147
But many tests are failing. If you can check it and let me know, if the fix is correct or not
Also how can I handle other tests, I need to change the tests or make some more changes in the fix
Flags: needinfo?(dustin)
| Reporter | ||
Updated•7 years ago
|
Flags: needinfo?(dustin)
| Reporter | ||
Comment 14•7 years ago
|
||
Releasing 12.8.0, and I'll deploy that in hooks.
| Reporter | ||
Comment 15•7 years ago
|
||
Comment 16•7 years ago
|
||
Commits pushed to master at https://github.com/taskcluster/taskcluster-hooks
https://github.com/taskcluster/taskcluster-hooks/commit/811be83b623059f93f3c14b29887ebb3547b3a6a
Bug 1437191 - use tc-lib-api with new error handling
https://github.com/taskcluster/taskcluster-hooks/commit/4b2a835eaee1e4426a4f94a8487257f385812791
Merge pull request #125 from djmitche/bug1437191
Bug 1437191 - use tc-lib-api with new error handling
| Reporter | ||
Comment 17•7 years ago
|
||
Seems to be working. I'm happy for the other services to get upgraded as we move to a monorepo :)
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Updated•7 years ago
|
Component: Platform Libraries → Services
You need to log in
before you can comment on or make changes to this bug.
Description
•