fix(config): name the rejected setting and its constraint in configuration errors
Every configuration failure projected the same message, "REA configuration is invalid. Run `rea doctor` and fix the reported setting.", with no details. The environment parser discarded the issue that names the variable (for example `REA_GHIDRA_NATIVEAOT_JAR must be absolute`), and doctor can report healthy for that environment, so neither the CLI, the MCP startup message, nor doctor told callers which setting to correct. ConfigurationError now carries the rejected settings and their constraints (never their values). The projection names them in its message, lists them in `details.settings`, and asks the caller to correct those settings where REA is started. Errors without a named setting keep the previous message. Fixes #1184 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
e6abaefbbc
commit
0a0244db42
@@ -53,9 +53,15 @@ export const parseEnvironment = (
|
||||
): Result<Environment, ConfigurationError> => {
|
||||
const parsed = environmentSchema.safeParse(environment);
|
||||
if (!parsed.success) {
|
||||
// Zod messages name the constraint, never the rejected value.
|
||||
const settings = parsed.error.issues.map((issue) => ({
|
||||
setting: String(issue.path[0] ?? "environment"),
|
||||
constraint: issue.message,
|
||||
}));
|
||||
return err(
|
||||
new ConfigurationError("Invalid REA environment configuration", {
|
||||
cause: parsed.error,
|
||||
settings,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@ export const mcpResponseBudgetSchema = z
|
||||
.transform(Number)
|
||||
.pipe(z.number().int().safe().min(MINIMUM_RESPONSE_BYTES));
|
||||
|
||||
const budgetConstraint = `REA_MCP_MAX_RESPONSE_BYTES must be a decimal safe integer at least ${String(MINIMUM_RESPONSE_BYTES)} bytes, the default stdio receive-buffer size.`;
|
||||
|
||||
/** Parse only the MCP-specific budget without loading unrelated provider settings. */
|
||||
export const parseMcpResponseBudget = (
|
||||
value: string | undefined,
|
||||
@@ -24,8 +26,13 @@ export const parseMcpResponseBudget = (
|
||||
return parsed.success
|
||||
? ok(parsed.data)
|
||||
: err(
|
||||
new ConfigurationError(
|
||||
`REA_MCP_MAX_RESPONSE_BYTES must be a decimal safe integer at least ${String(MINIMUM_RESPONSE_BYTES)} bytes, the default stdio receive-buffer size.`,
|
||||
),
|
||||
new ConfigurationError(budgetConstraint, {
|
||||
settings: [
|
||||
{
|
||||
setting: "REA_MCP_MAX_RESPONSE_BYTES",
|
||||
constraint: budgetConstraint,
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
+28
-2
@@ -14,10 +14,21 @@ export const parseStringArray = (
|
||||
: err(
|
||||
new ConfigurationError(`${name} must encode an array of strings`, {
|
||||
cause: parsed.error,
|
||||
settings: [
|
||||
{
|
||||
setting: name,
|
||||
constraint: `${name} must encode an array of strings`,
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
} catch (cause: unknown) {
|
||||
return err(new ConfigurationError(`${name} must be valid JSON`, { cause }));
|
||||
return err(
|
||||
new ConfigurationError(`${name} must be valid JSON`, {
|
||||
cause,
|
||||
settings: [{ setting: name, constraint: `${name} must be valid JSON` }],
|
||||
}),
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -32,6 +43,9 @@ export const parseLoaderArgs = (
|
||||
return err(
|
||||
new ConfigurationError("HOPPER_LOADER_ARGS_JSON must be valid JSON", {
|
||||
cause,
|
||||
settings: [
|
||||
loaderArgsIssue("HOPPER_LOADER_ARGS_JSON must be valid JSON"),
|
||||
],
|
||||
}),
|
||||
);
|
||||
}
|
||||
@@ -41,7 +55,19 @@ export const parseLoaderArgs = (
|
||||
: err(
|
||||
new ConfigurationError(
|
||||
"HOPPER_LOADER_ARGS_JSON must encode an array of strings",
|
||||
{ cause: parsed.error },
|
||||
{
|
||||
cause: parsed.error,
|
||||
settings: [
|
||||
loaderArgsIssue(
|
||||
"HOPPER_LOADER_ARGS_JSON must encode an array of strings",
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
);
|
||||
};
|
||||
|
||||
const loaderArgsIssue = (constraint: string) => ({
|
||||
setting: "HOPPER_LOADER_ARGS_JSON",
|
||||
constraint,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user