* Read JSON file from workspace session directory. * Returns null if file doesn't exist (not an error).
(workspaceId: string)
| 44 | * Returns null if file doesn't exist (not an error). |
| 45 | */ |
| 46 | async read(workspaceId: string): Promise<T | null> { |
| 47 | try { |
| 48 | const filePath = this.getFilePath(workspaceId); |
| 49 | const data = await fs.readFile(filePath, "utf-8"); |
| 50 | return JSON.parse(data) as T; |
| 51 | } catch (error) { |
| 52 | if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") { |
| 53 | return null; // File doesn't exist |
| 54 | } |
| 55 | // Log other errors but don't fail |
| 56 | log.error(`Error reading ${this.fileName}:`, error); |
| 57 | return null; |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Write JSON file to workspace session directory with file locking. |