Skip to content

Commit

Permalink
fix: add console logs to config file writes for troubleshooting plugi…
Browse files Browse the repository at this point in the history
…n-org NUTs
  • Loading branch information
shetzel committed Apr 30, 2024
1 parent d6430c0 commit e79f343
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/config/configFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ export class ConfigFile<
*/
public async write(): Promise<P> {
const lockResponse = await lockInit(this.getPath());
if (this.getPath().endsWith('sandbox-create-cache.json')) {
console.log('(async) time before write:', performance.now());
}

// lock the file. Returns an unlock function to call when done.
try {
Expand All @@ -246,6 +249,11 @@ export class ConfigFile<
}
// write the merged LWWMap to file
await lockResponse.writeAndUnlock(JSON.stringify(this.getContents(), null, 2));
if (this.getPath().endsWith('sandbox-create-cache.json')) {
console.log('(async) time after write:', performance.now());
console.dir(this.getContents(), { depth: 8 });
console.log('--------------------------------------');
}

return this.getContents();
}
Expand All @@ -258,17 +266,26 @@ export class ConfigFile<
*/
public writeSync(): P {
const lockResponse = lockInitSync(this.getPath());
if (this.getPath().endsWith('sandbox-create-cache.json')) {
console.log('(sync) time before write:', performance.now());
}
try {
// get the file modstamp. Do this after the lock acquisition in case the file is being written to.
const fileTimestamp = fs.statSync(this.getPath(), { bigint: true }).mtimeNs;
const fileContents = parseJsonMap<P>(fs.readFileSync(this.getPath(), 'utf8'), this.getPath());

this.logAndMergeContents(fileTimestamp, fileContents);
} catch (err) {
this.handleWriteError(err);
}

// write the merged LWWMap to file
lockResponse.writeAndUnlock(JSON.stringify(this.getContents(), null, 2));
if (this.getPath().endsWith('sandbox-create-cache.json')) {
console.log('(sync) time after write:', performance.now());
console.dir(this.getContents(), { depth: 8 });
console.log('--------------------------------------');
}

return this.getContents();
}
Expand Down

0 comments on commit e79f343

Please sign in to comment.