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

Problem doing manual error reporting #64

Open
murphyke opened this issue Jan 7, 2019 · 4 comments
Open

Problem doing manual error reporting #64

murphyke opened this issue Jan 7, 2019 · 4 comments

Comments

@murphyke
Copy link

murphyke commented Jan 7, 2019

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
Copy link
Collaborator

steren commented Jan 22, 2019

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
Copy link
Author

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

@bz2
Copy link
Contributor

bz2 commented Jun 11, 2019

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 stacktracejs/stacktrace-gps#54 which is another problem with this part of the JS parsing.

@ernsheong
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants
@steren @murphyke @bz2 @ernsheong and others