add optional chaining in response to sentry logs#62
add optional chaining in response to sentry logs#62nosovk wants to merge 1 commit intoMacFJA:mainfrom
Conversation
|
The StorageInterface interface declaration/**
* Storage interface
*/
export interface StorageInterface<T> {
/**
* Get a value from the storage.
*
* If the value doesn't exist in the storage, `null` should be returned.
* This method MUST be synchronous.
* @param key The key/name of the value to retrieve
*/
getValue(key: string): T | null
/**
* Save a value in the storage.
* @param key The key/name of the value to save
* @param value The value to save
*/
setValue(key: string, value: T): void
/**
* Remove a value from the storage
* @param key The key/name of the value to remove
*/
deleteValue(key: string): void
}To add the optional chaining to make code works, indicate that the compiler didn't do its job and allowed an invalid value. Furthermore, the storage can't be defined later, so the nothing will ever be persisted in this case If you need to conditionally set a storage, and need a "fallback" storage, you can use the |
|
Hm, I was using library within createLocalStorage, but because it's missing in some environments we got crashes in sentry. If there is an option to pass noop as a fallback it would be nice. Now, without that optional chaining it just throws exception and page stops loading. I think that not persisting data is better then unhandled exception. |
The issue seem to be here instead. The Do you have more details about the environment that create the crashes ? |
|
It was safari mobile, I think it was private session in it. It seems that before latest releases localStorage was or absent, or with 0 size available. |
|
Like this https://developer.mozilla.org/en-US/docs/Web/API/StorageManager/estimate returning 0 for local storage. |
Time to time there are errors in sentry: