Skip to content

Commit

Permalink
fix(agent): fix agent datafile readjson return empty instead of null. (
Browse files Browse the repository at this point in the history
  • Loading branch information
icycodes authored Oct 5, 2024
1 parent 42e1ced commit f6b64b0
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions clients/tabby-agent/src/dataStore/dataFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { isBrowser } from "../env";
import { getLogger } from "../logger";

export class FileDataStore extends EventEmitter {
private readonly logger = getLogger("DataStore");
private watcher?: ReturnType<typeof chokidar.watch>;

constructor(private readonly filepath: string) {
Expand All @@ -15,9 +16,10 @@ export class FileDataStore extends EventEmitter {

async read(): Promise<unknown> {
try {
return await fs.readJson(this.filepath, { throws: false });
const json = await fs.readJson(this.filepath, { throws: false });
return json ?? {};
} catch (err) {
getLogger().warn(`Failed to read ${this.filepath}: ${err}`);
this.logger.warn(`Failed to read ${this.filepath}: ${err}`);
return {};
}
}
Expand Down

0 comments on commit f6b64b0

Please sign in to comment.