Skip to content

Commit

Permalink
ignore file not found error when updating the file
Browse files Browse the repository at this point in the history
  • Loading branch information
yuetloo committed Jan 23, 2024
1 parent 6d70868 commit c711ce4
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion contracts/utils/JSONFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ export class JSONFile {
* @param data The new data to add to the JSON content
*/
static update(path: string, data: any) {
const state = JSONFile.read(path)
let state: any
try {
state = JSONFile.read(path)
} catch {
state = {}
}
fs.writeFileSync(path, JSON.stringify({ ...state, ...data }, null, 2))
}

Expand Down

0 comments on commit c711ce4

Please sign in to comment.