Search code examples
javascriptgoogle-cloud-platformstackdrivererror-reportinggoogle-cloud-error-reporting

How to send a error in google error reporting with no reportLocation


I'm trying to report errors using the Google Cloud Error Reporting api. I want log them with their stackTrace. I do not want to use context.reportLocation

It is mentioned here that

message:string [Required] The error message. If no context.reportLocation is provided, the message must contain a header (typically consisting of the exception type name and an error message) and an exception stack trace in one of the supported programming languages and formats.

There is no example provided as to how to use the message field instead of context.reportLocation.

I tried getting the current stacktrace and stringifying it to pass to message field. But I kept getting the following error:

INVALID_ARGUMENT: ReportedErrorEvent.context must contain a location unless `message` contain an exception or stacktrace.

The actual error I want to report would be in string format coming in request payload. Can anybody show an example with proper format for a JavaScript?


Solution

  • My preferred approach is to:

    1. Start with APIs Explorer
    2. Lookup the API e.g. Error Reporting
    3. Find the method e.g. report
    4. Use the documentation to understand the request (ReportedErrorEvent) and response types

    In this case ReportedErrorEvent contains message and this explains how to use it for various languages:

    JavaScript: Must be the value of error.stack as returned by V8.