From a191e0f08f58054615c40e3652c1c21cf54603e7 Mon Sep 17 00:00:00 2001 From: Meng Zhang Date: Sat, 5 Oct 2024 09:17:52 +0800 Subject: [PATCH] fix(agent): fix FileDataStore initialization (#3235) --- clients/tabby-agent/src/dataStore/dataFile.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/clients/tabby-agent/src/dataStore/dataFile.ts b/clients/tabby-agent/src/dataStore/dataFile.ts index c26e21ad407c..8c9f8536cb8e 100644 --- a/clients/tabby-agent/src/dataStore/dataFile.ts +++ b/clients/tabby-agent/src/dataStore/dataFile.ts @@ -4,6 +4,7 @@ import os from "os"; import fs from "fs-extra"; import chokidar from "chokidar"; import { isBrowser } from "../env"; +import { getLogger } from "../logger"; export class FileDataStore extends EventEmitter { private watcher?: ReturnType; @@ -13,7 +14,12 @@ export class FileDataStore extends EventEmitter { } async read(): Promise { - return (await fs.readJson(this.filepath, { throws: false })) || {}; + try { + return await fs.readJson(this.filepath, { throws: false }); + } catch (err) { + getLogger().warn(`Failed to read ${this.filepath}: ${err}`); + return {}; + } } async write(data: unknown) {