mirror of
https://github.com/moltbot/moltbot.git
synced 2026-03-30 01:06:11 +00:00
Config: fail closed invalid config loads
This commit is contained in:
@@ -4,6 +4,7 @@ export {
|
||||
createConfigIO,
|
||||
getRuntimeConfigSnapshot,
|
||||
loadConfig,
|
||||
readBestEffortConfig,
|
||||
parseConfigJson5,
|
||||
readConfigFileSnapshot,
|
||||
readConfigFileSnapshotForWrite,
|
||||
|
||||
@@ -810,7 +810,7 @@ export function createConfigIO(overrides: ConfigIoDeps = {}) {
|
||||
}
|
||||
const error = err as { code?: string };
|
||||
if (error?.code === "INVALID_CONFIG") {
|
||||
return {};
|
||||
throw err;
|
||||
}
|
||||
deps.logger.error(`Failed to read config at ${configPath}`, err);
|
||||
return {};
|
||||
@@ -1372,6 +1372,11 @@ export function loadConfig(): OpenClawConfig {
|
||||
return config;
|
||||
}
|
||||
|
||||
export async function readBestEffortConfig(): Promise<OpenClawConfig> {
|
||||
const snapshot = await readConfigFileSnapshot();
|
||||
return snapshot.valid ? loadConfig() : snapshot.config;
|
||||
}
|
||||
|
||||
export async function readConfigFileSnapshot(): Promise<ConfigFileSnapshot> {
|
||||
return await createConfigIO().readConfigFileSnapshot();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user