GoogleCloudPlatform / stackdriver-errors-js

Client-side JavaScript exception reporting library for Cloud Error Reporting
https://cloud.google.com/error-reporting/
Apache License 2.0
362 stars 54 forks source link

Problem doing manual error reporting #64

Open murphyke opened 5 years ago

murphyke commented 5 years ago

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.

steren commented 5 years ago

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?

murphyke commented 5 years ago

I am cranking for a deadline but will make a reminder to look at this ... hopefully next week.

bz2 commented 5 years ago

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.

ernsheong commented 3 years ago

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"
  }
}