stackdriver-errors-js
stackdriver-errors-js copied to clipboard
Problem doing manual error reporting
Hi, I have code that does:
// In a promise `then` handler:
myRegister(new Error('some error'));
// ...
// Elsewhere in the code:
errorHandler.report(theNewError);
but the stackdriver API response is:
{
"error": {
"code": 400,
"message": "ReportedErrorEvent.context must contain a location unless `message` contain an exception or stacktrace.",
"status": "INVALID_ARGUMENT"
}
}
The request that is sent to stackdriver is:
{
"serviceContext": {"service": "webApp", "version": "whatever"},
"context": {
"user": "Joe User",
"httpRequest": {
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36",
"url": "http://localhost:3000/"
}
},
"message": "Error: {\"type\":\"An error during API handling\"}\n at then(function (/Users/murphyke/Documents/code/myapp/web/src/actions.js:224:0)"
};
What is the recommendation? Do I have to annotate the error object somehow?
Unhandled exceptions are reported correctly.
Using Chrome, btw.
It seems that the message attribute is not recognized as being an exception by Stackdriver Error Reporting.
Stackdriber Error Reporting expects stacktraces formatted as such
Would you mind providing an exact sample that reproduces the issue?
I am cranking for a deadline but will make a reminder to look at this ... hopefully next week.
I have reproduced this in our deployment, issue is not related to calling report directly, but comes from stacktrace-gps producing invalid function names.
Example response:
{
"error": {
"code": 400,
"message": "ReportedErrorEvent.context must contain a location unless `message` contain an exception or stacktrace.",
"status": "INVALID_ARGUMENT"
}
}
Example message from request:
TypeError: Cannot read property 'removeLayer' of null
at window.setTimeout(function (webpack:///node_modules/prunecluster/dist/PruneCluster.js:938:0)
The section of code from PruneCluster:
window.setTimeout(function () {
for (i = 0, l = markers.length; i < l; ++i) {
_this._map.removeLayer(markers[i]);
}
}, 300);
This would be correctly reported as <anonymous> but has instead given 'window.setTimeout(function' as the function name.
Workarounds at the stackdriver-errors-js level are possible, if a bit awkward? Could use something like isVarName to strip out badly detection function names.
See also https://github.com/stacktracejs/stacktrace-gps/issues/54 which is another problem with this part of the JS parsing.
Seeing something similar in 0.8.0:
Payload:
{
"serviceContext":{"service":"web"},
"context":{"httpRequest":{"userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36","url":"https://app.DOMAIN.com/tracks/91"}},
"message":"TypeError: Cannot read property 'querySelectorAll' of null\n at _loadArchivedCards(t){this.store.dispatch(Object(h.g)(this.stage.trackId,{stageId:this.stage.id,archived:!0})).then(()=>{Object(F.a) (https://app.DOMAIN.com/6.49bfb0b2404f25c0f4e0.bundle.js:515:1420)"
}
Response:
{
"error": {
"code": 400,
"message": "ReportedErrorEvent.context must contain a location unless `message` contain an exception or stacktrace.",
"status": "INVALID_ARGUMENT"
}
}