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

TypeError "sdk" is read-only when calling Sentry.captureException() #4711

Closed
3 tasks done
aaptho opened this issue Mar 12, 2022 · 3 comments
Closed
3 tasks done

TypeError "sdk" is read-only when calling Sentry.captureException() #4711

aaptho opened this issue Mar 12, 2022 · 3 comments
Labels
Package: core Issues related to the Sentry Core SDK Type: Bug

Comments

@aaptho
Copy link

aaptho commented Mar 12, 2022

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which package are you using?

@sentry/nextjs

SDK Version

6.18.2

Framework Version

No response

Link to Sentry event

https://sentry.io/organizations/spatial/issues/3090469778/?environment=qa-preview&environment=dev&environment=dev-preview&environment=development&project=6093190&query=is%3Aunresolved&statsPeriod=1h

Steps to Reproduce

Our project uses Unity built to WebGL, and capture any exceptions it throws.

In that error handler, we call Sentry.captureException(error), which causes the error below.

Expected Result

The error is sent off to Sentry and appears in our organization's dashboard under Issues

Actual Result

An issue appears in the Sentry dashboard, but instead of the Unity error, there seems to be an error in @sentry/core:

TypeError: "sdk" is read-only
  at enhanceEventWithSdkInfo(webpack-internal:///../../node_modules/@sentry/core/esm/request.js:28:19)
  at eventToSentryRequest(webpack-internal:///../../node_modules/@sentry/core/esm/request.js:71:28)
  at BaseTransport.prototype.sendEvent(webpack-internal:///../../node_modules/@sentry/browser/esm/transports/base.js:43:100)
  at BaseBackend.prototype.sendEvent(webpack-internal:///../../node_modules/@sentry/core/esm/basebackend.js:39:30)
  at BaseClient.prototype._sendEvent(webpack-internal:///../../node_modules/@sentry/core/esm/baseclient.js:405:28)
  at BrowserClient.prototype._sendEvent(webpack-internal:///../../node_modules/@sentry/browser/esm/client.js:80:37)
  at BaseClient.prototype._processEvent/<(webpack-internal:///../../node_modules/@sentry/core/esm/baseclient.js:477:19)
  at SyncPromise.prototype.then/</<(webpack-internal:///../../node_modules/@sentry/utils/esm/syncpromise.js:107:37)
  at SyncPromise/this._executeHandlers/<(webpack-internal:///../../node_modules/@sentry/utils/esm/syncpromise.js:78:31)
  at SyncPromise/this._executeHandlers(webpack-internal:///../../node_modules/@sentry/utils/esm/syncpromise.js:72:28)
  at SyncPromise.prototype.then/<(webpack-internal:///../../node_modules/@sentry/utils/esm/syncpromise.js:128:19)
  at SyncPromise(webpack-internal:///../../node_modules/@sentry/utils/esm/syncpromise.js:87:21)
  at SyncPromise.prototype.then(webpack-internal:///../../node_modules/@sentry/utils/esm/syncpromise.js:96:16)
  at BaseClient.prototype._processEvent(webpack-internal:///../../node_modules/@sentry/core/esm/baseclient.js:468:14)
  at BaseClient.prototype._captureEvent(webpack-internal:///../../node_modules/@sentry/core/esm/baseclient.js:414:21)
  at BaseClient.prototype.captureException/<(webpack-internal:///../../node_modules/@sentry/core/esm/baseclient.js:79:51)
  at SyncPromise.prototype.then/</<(webpack-internal:///../../node_modules/@sentry/utils/esm/syncpromise.js:107:37)
  at SyncPromise/this._executeHandlers/<(webpack-internal:///../../node_modules/@sentry/utils/esm/syncpromise.js:78:31)
  at SyncPromise/this._executeHandlers(webpack-internal:///../../node_modules/@sentry/utils/esm/syncpromise.js:72:28)
  at SyncPromise.prototype.then/<(webpack-internal:///../../node_modules/@sentry/utils/esm/syncpromise.js:128:19)
  at SyncPromise(webpack-internal:///../../node_modules/@sentry/utils/esm/syncpromise.js:87:21)
  at SyncPromise.prototype.then(webpack-internal:///../../node_modules/@sentry/utils/esm/syncpromise.js:96:16)
  at BaseClient.prototype.captureException(webpack-internal:///../../node_modules/@sentry/core/esm/baseclient.js:79:14)
  at Hub.prototype._invokeClient(webpack-internal:///../../node_modules/@sentry/hub/esm/hub.js:397:35)
  at Hub.prototype.captureException(webpack-internal:///../../node_modules/@sentry/hub/esm/hub.js:147:14)
  at callOnHub(webpack-internal:///../../node_modules/@sentry/minimal/esm/index.js:36:28)
  at captureException(webpack-internal:///../../node_modules/@sentry/minimal/esm/index.js:55:12)
  at errorHandler(webpack-internal:///../../libs/web-core/src/js/components/spatial-unity-web-gl/unity-client-saga/unity-client-saga.ts:101:52)
@lobsterkatie
Copy link
Member

Hi, @aaptho.

Thanks for reporting this. It's puzzling. The code that's erroring is here:

/**
* Apply SdkInfo (name, version, packages, integrations) to the corresponding event key.
* Merge with existing data if any.
**/
function enhanceEventWithSdkInfo(event: Event, sdkInfo?: SdkInfo): Event {
if (!sdkInfo) {
return event;
}
event.sdk = event.sdk || {};
event.sdk.name = event.sdk.name || sdkInfo.name;
event.sdk.version = event.sdk.version || sdkInfo.version;
event.sdk.integrations = [...(event.sdk.integrations || []), ...(sdkInfo.integrations || [])];
event.sdk.packages = [...(event.sdk.packages || []), ...(sdkInfo.packages || [])];
return event;
}

It's touching the event's sdk property, which is first set here:

/**
* This function adds all used integrations to the SDK info in the event.
* @param event The event that will be filled with all integrations.
*/
protected _applyIntegrationsMetadata(event: Event): void {
const integrationsArray = Object.keys(this._integrations);
if (integrationsArray.length > 0) {
event.sdk = event.sdk || {};
event.sdk.integrations = [...(event.sdk.integrations || []), ...integrationsArray];
}
}

as part of the _prepareEvent method on the client class, which is run on all events.

I'm not very familiar with Unity or WebGL, but given that this code a) isn't new, and b) is run on every event sent by the SDK, I have to assume that the answer lies there, or we'd've gotten lots more reports before this. From what you know about them, does an object's property becoming read-only ring any bells?

(I don't think it's the SDK property specifically that's the problem. It's just the first property that eventToSentryRequest touches.)

@bruno-garcia
Copy link
Member

It doesn't seem possible that this issue is created by the JS SDK itself. We'll take a look into Unity's WebGL to see if we can figure out what's going on. Worth noting we plan on adding support to WebGL on the Sentry SDK for Unity, even though the first version might not bundle the JS SDK (it'll capture C# scripting errors only)

@aaptho
Copy link
Author

aaptho commented Mar 15, 2022

Further debugging showed that the issue was indeed on our end.

We were using Redux to store the most recent Sentry event, in order to associate it with a custom user feedback report UI. For some reason, React’s dispatch was freezing this event once we stored it in the Redux state, which later caused this issue.

Either way, exciting to hear you plan on supporting Unity WebGL more directly!

Thank you both kindly for the help investigating this!

@aaptho aaptho closed this as completed Mar 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: core Issues related to the Sentry Core SDK Type: Bug
Projects
Archived in project
Development

No branches or pull requests

3 participants