question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

notify callback parameters name are confusing

See original GitHub issue

Describe the bug

When calling bugnsag.notify, I pass a a callback to add metadata. These pieces of metadata don’t seem to be sent to bugsnag. Stepping through teh code, it looks like they should be getting added, though printing the event object at the end of the callback shows that they were not.

Steps to reproduce

in a react native app add:

 captureError(params: CaptureErrorParams): void {
    const { error, message, extra, sendToServer } = params;

    const addMessageAsContext: (error: any, event: Event) => void = (
      _error,
      event
    ) => {
      event.context = message;

      //convert the dictionary into metadata
      if (params.extra != null) {
        for (const [sectionKey, sectionData] of Object.entries(params.extra)) {
          for (const [key, value] of Object.entries(sectionData)) {
            event.addMetadata(sectionKey, key, value);
          }
        }
      }

      //eslint-disable-next-line no-console
      console.log('callback: ', event.getMetadata('great'));   <======prints undefined
    };

 this.bugsnagClient.notify(
          JSON.stringify(error),
          undefined,
          addMessageAsContext
        );
}


    captureError({
      message: 'message',
      error: new Error('error name'),
      extra: { great: { details: 'detailed answer' } },
    });

I stepped through addMetadata and it seems that state[section] = assign({}, state[section], updates) has no effect. I added console.log(state) right after it and it still has the original content, no trace of the extra metadata: {"app": {"name": "xxx"}, "device": {"simulator": true, "thermalState": "nominal", "timezone": "GMT+1", "wordSize": 64}}

Environment

  • Bugsnag version: “@bugsnag/react-native”: “^7.16.0”,
  • Browser framework version (if any):
    • React:“react”: “17.0.2”,
  • Device (e.g. iphonex): simulator

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
otuswebcommented, Feb 9, 2022

Thanks for clarifying @imjoehaines . It’s a case of not understanding the parameter’s names on my end then.

I understood onError to be a callback called when an error was thrown while sending the event to the server. cb just did not mean anything to me, so I used it.

Can I suggest renaming those parameters:

  • onReadyToSend instead of onError, or anything that relates that it is called before the event is sent to offer configuration opportunity
  • onSent instead of cb or anything that indicates this is called when the event has been sent

Thanks for helping me figure it out

1reaction
imjoehainescommented, Feb 9, 2022

Hey @otusweb, there are two different kinds of callbacks that notify accepts:

Generally you’ll want to use the onError callback as it allows you to make changes to the event before sending it

I hope that clears things up!

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - Callback function confusion - Stack Overflow
The callback function gets called when the data has been read from the mongoose connection. The data is passed to the fruits argument....
Read more >
notifyOutputChanged: () => void ? - Power Platform Community
I understand it is a callback method that we need to call to notify the runtime framework that there are changes in the...
Read more >
What do you name the callback function? - Freek.dev
I do use different names for the callback parameter, depending on the ... of the name, people will be confused and it will...
Read more >
Callback Functions in JavaScript - Impressive Webs
An overview with live code examples demonstrating how callback functions in JavaScript work and how they might be used in your code.
Read more >
Understand JavaScript Callback Functions and Use Them
Even without a name, it can still be accessed later via the arguments object by the containing function. Callback Functions Are Closures When...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found