mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-27 18:01:46 +00:00
fix(plugins): address review feedback for Matrix recovery paths (#52899)
1. Narrow loadConfigForInstall() to catch only INVALID_CONFIG errors, letting real failures (fs permission, OOM) propagate. 2. Assert allow array is properly cleaned in stale-cleanup test. 3. Add comment clarifying version-resolution is already addressed via the shared VERSION constant. 4. Run cleanStaleMatrixPluginConfig() during install so persistPluginInstall() → writeConfigFile() does not fail validation on stale Matrix load paths.
This commit is contained in:
committed by
Peter Steinberger
parent
3ae100a8d7
commit
489797ceaf
@@ -1,4 +1,5 @@
|
||||
import fs from "node:fs";
|
||||
import { cleanStaleMatrixPluginConfig } from "../commands/doctor/providers/matrix.js";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { loadConfig, readBestEffortConfig } from "../config/config.js";
|
||||
import { installHooksFromNpmSpec, installHooksFromPath } from "../hooks/install.js";
|
||||
@@ -170,12 +171,28 @@ async function tryInstallHookPackFromNpmSpec(params: {
|
||||
// loadConfig() throws when config is invalid; fall back to best-effort so
|
||||
// repair-oriented installs (e.g. reinstalling a broken Matrix plugin) can
|
||||
// still proceed from a partially valid config snapshot.
|
||||
// Only catch config-validation errors — real failures (fs permission, OOM)
|
||||
// must surface so the user sees the actual problem.
|
||||
// After loading, clean any stale Matrix plugin references so that
|
||||
// persistPluginInstall() → writeConfigFile() does not fail validation
|
||||
// on paths that no longer exist (#52899 concern 4).
|
||||
async function loadConfigForInstall(): Promise<OpenClawConfig> {
|
||||
let cfg: OpenClawConfig;
|
||||
try {
|
||||
return loadConfig();
|
||||
} catch {
|
||||
return readBestEffortConfig();
|
||||
cfg = loadConfig();
|
||||
} catch (err) {
|
||||
if (isConfigValidationError(err)) {
|
||||
cfg = await readBestEffortConfig();
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
const cleaned = await cleanStaleMatrixPluginConfig(cfg);
|
||||
return cleaned.config;
|
||||
}
|
||||
|
||||
function isConfigValidationError(err: unknown): boolean {
|
||||
return err instanceof Error && (err as { code?: string }).code === "INVALID_CONFIG";
|
||||
}
|
||||
|
||||
export async function runPluginInstallCommand(params: {
|
||||
|
||||
Reference in New Issue
Block a user