getsentry / sentry-javascript-bundler-plugins

JavaScript Bundler Plugins for Sentry
https://sentry.io
BSD 3-Clause "New" or "Revised" License
142 stars 37 forks source link

`ErrorBoundary` causing missing `debug_meta` from being sent alongside errors #621

Open ash-plunkett-alliance opened 1 month ago

ash-plunkett-alliance commented 1 month ago

Environment

Production dependencies:

"@sentry/browser": "^8.34.0",
"@sentry/react": "^8.34.0",
"@sentry/tracing": "^7.114.0",

Dev dependencies:

"@sentry/cli": "^2.37.0",
"@sentry/webpack-plugin": "^2.22.5",

Using Sentry as SaaS (sentry.io).

Steps to Reproduce

Use Sentry's ErrorBoundary, eg:

// ErrorBoundary.js
export default function ErrorBoundary({ children }) {
    // Simple usage, no dialog/modal or fallback
    return (
        <Sentry.ErrorBoundary>
            {children}
        </Sentry.ErrorBoundary>
    );
}

ErrorBoundary.propTypes = {
    children: PropTypes.node.isRequired,
};
// MyEntryPointComponent.js
export default function MyEntryPointComponent() {
    return (
        <ErrorBoundary>
            <OtherComponent ... />
        </ErrorBoundary>
    );
}

Expected Result

Sourcemap magic is worked and the stack trace shown for the error in Sentry is unminified.

Actual Result

Sourcemap magic isn't workable as there is no debug_meta posted alongside the error.

Looking at the network requests being sent from the browser to Sentry when an error happens (inside of <OtherComponent />), it's successfully caught by Sentry, but there is no debug_meta information at all. This means that Sentry can't link everything together as expected.

Some notes:

Every other method of error catching & reporting works as expected as far as I can tell, eg to lay them all out in one example that should be easy enough to be reproducible:

function MyComponent() {
    // this will throw an error, if not using an ErrorBoundary around this component then it does have `debug_meta` posted
    // as soon as there is an ErrorBoundary wrapped around this though, then when this code throws its usual error, there is no `debug_meta`
    const foo = undefined;
    foo.bar = 'baz';

    // if you comment out the above erroneous code, then we move on to all the working examples, all of which have `debug_meta`
    // (regardless of if there's a wrapping ErrorBoundary or not)

    // async callbacks also work as expected, regardless of there being a wrapping ErrorBoundary or not
    // if there's an error in the callback which consumes the websocket message, that error is logged as expected
    const onMessage = (...) => {
        // just some garbage to throw an error
        const foo = undefined;
        foo.bar = 'baz';
    };
    useWebsocketConnection(..., onMessage);

    // and some easy-to-trigger onclick's testing other scenarios:
    return (
        <>
            <a
                href="#"
                onClick={() => {
                    console.foo('aaa');
                }}
            >
                Unhandled error, undefined property
            </a>

            <a
                href="#"
                onClick={() => {
                    Sentry.captureEvent({
                        message: 'Manually captured Sentry event',
                        level: 'debug',
                        extra: {
                            foo: 'bar',
                            alice: 'cooper',
                        },
                    });
                }}
            >
                Custom Sentry event
            </a>

            <a
                href="#"
                onClick={() => {
                    throw new Error('manual error thrown');
                }}
            >
                Manual uncaught error thrown
            </a>

            <a
                href="#"
                onClick={() => {
                    const foo = undefined;
                    foo.bar = 'baz';
                }}
            >
                Deliberate error
            </a>
        </>
    );
}

Let me know if you need any more information. I'd be happy to email/privately share links to specific events, data being posted from the browser -> sentry.io, etc.

lforst commented 1 month ago

Thanks for writing in!

getsantry[bot] commented 3 days ago

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you remove the label Waiting for: Community, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀