Skip to content

fix: use a static object as fallback of the global object #1901

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

Merged
merged 2 commits into from
Feb 19, 2019

Conversation

Means88
Copy link
Contributor

@Means88 Means88 commented Feb 19, 2019

I'm working on Mini Program (in WeChat etc.), which is not a Node environment nor standard browser environment.

console.log('window', typeof window) // undefined
console.log('process', typeof process) //undefined
console.log('global', typeof global) // object

The getGlobalObject function returns a new object every time when it is called, so that getMainCarrier and getCurrentHub return a new instance every time and remain uninitialized.

export function getMainCarrier(): Carrier {
const carrier: any = getGlobalObject();
carrier.__SENTRY__ = carrier.__SENTRY__ || {
hub: undefined,
};
return carrier;
}

export function getCurrentHub(): Hub {
// Get main carrier (global for every environment)
const registry = getMainCarrier();
// If there's no hub, or its an old API, assign a new one
if (!hasHubOnCarrier(registry) || getHubFromCarrier(registry).isOlderThan(API_VERSION)) {
setHubOnCarrier(registry, new Hub());
}

Exceptions will not be sent to server because client is not installed on the "current hub".

@Means88 Means88 requested a review from kamilogorek as a code owner February 19, 2019 09:16
@kamilogorek
Copy link
Contributor

Makes perfect sense. Thanks!

@kamilogorek kamilogorek merged commit bd35d73 into getsentry:master Feb 19, 2019
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

Successfully merging this pull request may close these issues.

2 participants