Skip to content

Commit

Permalink
fix: add defensive programming for malformed settings files
Browse files Browse the repository at this point in the history
Signed-off-by: tylerslaton <[email protected]>
  • Loading branch information
tylerslaton committed Sep 10, 2024
1 parent cead33b commit 4a406cf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion actions/appSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ export async function getAppSettings() {
const location = process.env.GPTSCRIPT_SETTINGS_FILE;
if (fs.existsSync(location)) {
const AppSettings = fs.readFileSync(location, 'utf-8');
return JSON.parse(AppSettings) as AppSettings;
try {
return JSON.parse(AppSettings) as AppSettings;
} catch {
console.error('Malformed settings file, using default settings...');
}
}
return defaultAppSettings;
}
Expand Down
6 changes: 5 additions & 1 deletion server/app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,11 @@ const mount = async (
},
};
if (existsSync(settingsLocation)) {
settings = JSON.parse(fs.readFileSync(settingsLocation, 'utf8'));
try {
settings = JSON.parse(fs.readFileSync(settingsLocation, 'utf8'));
} catch {
console.error('Malformed settings file, using default settings...');
}
}

let script;
Expand Down

0 comments on commit 4a406cf

Please sign in to comment.