Skip to content

Commit

Permalink
Slightly improve logging around failed init conditions (#1000)
Browse files Browse the repository at this point in the history
  • Loading branch information
eritbh committed Oct 10, 2024
1 parent 858dd58 commit 2850b51
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
20 changes: 16 additions & 4 deletions extension/data/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,26 @@ async function checkLoadConditions (tries = 3) {
}

// Check that we have details about the current user
const userDetails = await TBApi.getUserDetails();
let userDetails;
try {
userDetails = await TBApi.getUserDetails();
} catch (error) {
throw new Error('Failed to fetch user details', {cause: error});
}
if (!userDetails || userDetails.constructor !== Object || !Object.keys(userDetails).length) {
throw new Error('Failed to fetch user details');
throw new Error(`Fetched user details are invalid: ${userDetails}`);
}

// Write a setting and read back its value, if this fails something is wrong
if (await TBStorage.setSettingAsync('Utils', 'echoTest', 'echo') !== 'echo') {
throw new Error('Settings cannot be read/written');
let echoValue = Math.random();
let echoResult: number;
try {
echoResult = await TBStorage.setSettingAsync('Utils', 'echoTest', echoValue);
} catch (error) {
throw new Error('Failed to write to settings', {cause: error});
}
if (echoResult !== echoValue) {
throw new Error(`Settings read/write inconsistent: expected ${echoValue}, received ${echoResult}`);
}
}

Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "@tsconfig/recommended/tsconfig.json",
"compilerOptions": {
"target": "ESNext",
"allowJs": true,
// we only really care about rollup output, but if we leave this unset
// then tooling will complain about the tsconfig.json being invalid
Expand Down

0 comments on commit 2850b51

Please sign in to comment.