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

fix: Check for undefined faro instancein isWebStorageAvailable catch block #757

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

edkimmel
Copy link

@edkimmel edkimmel commented Dec 5, 2024

Why

If storage throws an exception during the module init calls to isWebStorageAvailable, the global faro instance is not set and this crashes.

What

Optional chain the faro instance itself in this catch block.

Links

Checklist

  • Tests added
  • Changelog updated
  • Documentation updated

@CLAassistant
Copy link

CLAassistant commented Dec 5, 2024

CLA assistant check
All committers have signed the CLA.

@edkimmel edkimmel changed the title Check for undefined faro instance fix | Check for undefined faro instance Dec 5, 2024
@edkimmel edkimmel changed the title fix | Check for undefined faro instance fix: Check for undefined faro instancein isWebStorageAvailable catch block Dec 5, 2024
Copy link
Collaborator

@kpelelis kpelelis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @edkimmel, thank you so much for your interest and support in the project, as well as the time you allocated to work on this. I really appreciate it, although this is a small change, would you be able to provide a screenshot or a log, or ideally a test case that this might fail? From my understanding, the faro instance will be instantatiated here.

To be clear, I am more than happy to merge this, but I am only marking it as 'Request changes' to make sure we resolve the conversation

@@ -25,7 +25,8 @@ export function isWebStorageAvailable(type: StorageMechanism): boolean {
return true;
} catch (error) {
// the above can throw
faro.internalLogger?.info(`Web storage of type ${type} is not available. Reason: ${error}`);
// this is called during module init, when the global instance may not be available
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not necessarily called during global module init if you would be able to rephrase the comment for clarity.

@edkimmel
Copy link
Author

The logs we are seeing on our end are TypeError: Cannot read property 'internalLogger' of undefined.

I have not been able to reproduce locally. Scanning through faro, I believe this is the only callsite that could produce that error. The other calls to faro.internalLogger all check some other property of the global faro instance (faro.config) first, which would be the line thrown from instead.

@kpelelis
Copy link
Collaborator

The logs we are seeing on our end are TypeError: Cannot read property 'internalLogger' of undefined.

I have not been able to reproduce locally. Scanning through faro, I believe this is the only callsite that could produce that error. The other calls to faro.internalLogger all check some other property of the global faro instance (faro.config) first, which would be the line thrown from instead.

Hey once again. I was on PTO last week so apologies for catching up with your replies a week later. Do you have any other stack traces that might be helpful? Although I am leaning towards your original change being the solution. I just want to get more context so that we can have precedence and ideally create a test for it

@codecapitano
Copy link
Collaborator

Hi @edkimmel want to follow up on this.

Do you still run into the issue?

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.

4 participants