diff --git a/src/commands/job.ts b/src/commands/job.ts index c5ff121..45b2de0 100644 --- a/src/commands/job.ts +++ b/src/commands/job.ts @@ -109,7 +109,9 @@ export function registerJobCommands(program: Command): void { ); for (const j of allJobs) { const budget = !j.legacy - ? formatUnits(BigInt(j.budget), 6) + ? j.budget + ? formatUnits(BigInt(j.budget), 6) + : "N/A" : j.budget; console.log( `${j.onChainJobId}\t${j.chainId}\t${j.clientAddress}\t${j.providerAddress}\t${budget}\t${j.jobStatus}\t${j.legacy}` diff --git a/src/lib/config.ts b/src/lib/config.ts index 863aced..60eb9a1 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -1,6 +1,6 @@ import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "fs"; import { homedir } from "os"; -import { resolve } from "path"; +import { join, resolve } from "path"; import { getPassword, setPassword, @@ -59,7 +59,12 @@ function loadConfig(): Config { function saveConfig(config: Config): void { mkdirSync(CONFIG_DIR, { recursive: true }); - writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2) + "\n"); + // Write to a temp file first, then atomically rename to the final path. + // This prevents a truncated/partial JSON file if the process is interrupted + // mid-write, which would make loadConfig return an empty object on next run. + const tmpPath = join(CONFIG_DIR, `${CONFIG_FILENAME}.tmp`); + writeFileSync(tmpPath, JSON.stringify(config, null, 2) + "\n"); + renameSync(tmpPath, CONFIG_PATH); } function isKeychainUnavailable(err: unknown): boolean {