Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export class RemoteConfigLocalStorage implements RemoteConfigStorage {
private readonly logger: ILogger;

constructor(apiKey: string, logger: ILogger) {
this.key = `AMP_remote_config_${apiKey.substring(0, 10)}`;
const apiKeyString = typeof apiKey === 'string' ? apiKey : '';
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Guard the later diagnostics storage construction too

For browser init calls that pass a non-string API key such as null or a number, this fallback prevents RemoteConfigLocalStorage from throwing, but the same _init path then constructs DiagnosticsClient, whose DiagnosticsStorage constructor still executes apiKey.substring(0, 10). In IndexedDB-capable browsers, the init promise can therefore still reject with the same TypeError after the remote-config subscription completes, so the customer-visible failure this change targets is not actually fixed for those inputs.

Useful? React with 👍 / 👎.

this.key = `AMP_remote_config_${apiKeyString.substring(0, 10)}`;
this.logger = logger;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,15 @@ describe('RemoteConfigLocalStorage', () => {
jest.restoreAllMocks();
});
});

describe('constructor', () => {
it.each([
['undefined', undefined],
['null', null],
['a number', 12345],
['an object', { apiKey: 'oops' }],
])('should not throw when apiKey is %s', (_label, badApiKey) => {
expect(() => new RemoteConfigLocalStorage(badApiKey as unknown as string, logger)).not.toThrow();
});
});
});
Loading