fix: write error messages as plain text (#1709)

## Summary

Removes the Markdown code spans from thirteen error messages. Schema
v2.0.0-beta.4 says that the `message` of an error is plain text, and
these messages put a field or capability name in backticks.

## Why only these

I checked every v2 field that the schema marks as plain text against
what the adapter sends for it: tool call and permission titles,
permission option names, elicitation messages and labels, auth method
names, config option names, command names and hints, session and
subagent titles, notices, compaction errors and error messages. Text
that the adapter composes is plain everywhere else. The Glob title
already drops its code spans on v2.

Not changed: text that the adapter passes on from the model, Claude
Code, an MCP server or the user, such as an AskUserQuestion question, a
Bash command in a title, a session title or Claude Code's error text.
The adapter does not rewrite it.

## The messages

All are `-32602` messages:

- `src/v2/agent.ts`: "cwd must be an absolute path" (two forms), "cwd is
not a directory: …", "… with that cwd"
- `src/v2/prompt.ts`: "prompt must hold at least one content block"
- `src/initial-config-options.ts`: "configOptions sets … more than once.
…"
- `src/fork-session.ts`: "… announced with the fork capability, or send
the request without cursorId …"
- `src/providers.ts`: the two `_meta.gateway` messages and the vertex
message
- `src/session-index/service.ts`: the three `_meta.jetbrains.air.list`
messages

The last four files are shared, so a v1 client gets the same text
without the backticks. v1's schema has no rule for it either way, and
one text for both versions needs no switch in each helper.

## Testing

- `npm run build` and `npm run check` pass. `npm run test:run` passed
before the rebase onto #1705 (4,485 tests; one file watcher test of
`v1/session-index.test.ts` failed once on a loaded machine and passed
three times by itself). No test pinned the old text.
This commit is contained in:
Ben Brandt
2026-11-24 16:05:18 +01:00
committed by GitHub
parent fa02bc239f
commit 2c37f979b6
6 changed files with 13 additions and 13 deletions

View File

@@ -216,7 +216,7 @@ async function forkTranscript(
if (upToMessageId === undefined) {
throw RequestError.invalidParams(
{ cursorId: params.cursorId },
`Session ${params.sessionId} has no cursor ${params.cursorId} that a fork can start at. Use a cursor that the session announced with the \`fork\` capability, or send the request without \`cursorId\` to fork the whole session.`,
`Session ${params.sessionId} has no cursor ${params.cursorId} that a fork can start at. Use a cursor that the session announced with the fork capability, or send the request without cursorId to fork the whole session.`,
);
}
const forked = await forkClaudeSession(params.sessionId, { upToMessageId });

View File

@@ -28,7 +28,7 @@ export function initialConfigOptions<E extends { configId: string }>(
if (seen.has(configId)) {
throw RequestError.invalidParams(
{ configId },
`\`configOptions\` sets ${configId} more than once. Send one entry for each config option.`,
`configOptions sets ${configId} more than once. Send one entry for each config option.`,
);
}
seen.add(configId);

View File

@@ -300,13 +300,13 @@ export function validatedGatewayAuthRequest(params: AuthenticateRequest): Gatewa
if (typeof gateway !== "object" || !isValidBaseUrl(gateway.baseUrl)) {
throw RequestError.invalidParams(
{ baseUrl: (gateway as { baseUrl?: unknown }).baseUrl },
"`_meta.gateway.baseUrl` must be a non-empty absolute http(s) URL.",
"_meta.gateway.baseUrl must be a non-empty absolute http(s) URL.",
);
}
if (gateway.headers !== undefined && typeof gateway.headers !== "object") {
throw RequestError.invalidParams(
undefined,
"`_meta.gateway.headers` must be an object of header names to values.",
"_meta.gateway.headers must be an object of header names to values.",
);
}
}
@@ -395,7 +395,7 @@ export function providerConfigFromSetRequest(params: SetProviderRequest): Provid
) {
throw RequestError.invalidParams(
undefined,
"vertex apiType requires non-empty `_meta.claudeCode.vertex.projectId` and `_meta.claudeCode.vertex.region`.",
"vertex apiType requires non-empty _meta.claudeCode.vertex.projectId and _meta.claudeCode.vertex.region.",
);
}
config.vertex = { projectId: vertex.projectId, region: vertex.region };

View File

@@ -138,7 +138,7 @@ function archivedFilter(list: Record<string, unknown>): ArchivedFilter {
if (!ARCHIVED_FILTERS.includes(value as ArchivedFilter)) {
throw RequestError.invalidParams(
{ archived: value },
'`_meta.jetbrains.air.list.archived` must be "unarchived", "archived" or "all"',
'_meta.jetbrains.air.list.archived must be "unarchived", "archived" or "all"',
);
}
return value as ArchivedFilter;
@@ -150,7 +150,7 @@ function optionalBoolean(list: Record<string, unknown>, key: string): boolean {
if (typeof value !== "boolean") {
throw RequestError.invalidParams(
{ [key]: value },
`\`_meta.jetbrains.air.list.${key}\` must be a boolean`,
`_meta.jetbrains.air.list.${key} must be a boolean`,
);
}
return value;
@@ -165,7 +165,7 @@ export function parseListOptions(meta: unknown): ListOptions {
if (typeof raw !== "number" || !Number.isInteger(raw) || raw < 1) {
throw RequestError.invalidParams(
{ limit: raw },
"`_meta.jetbrains.air.list.limit` must be an integer of at least 1",
"_meta.jetbrains.air.list.limit must be an integer of at least 1",
);
}
return {

View File

@@ -644,7 +644,7 @@ class V2Agent implements AgentHandle, SessionConnection {
async listSessions(params: v2.ListSessionsRequest): Promise<v2.ListSessionsResponse> {
if (params.cwd != null && !path.isAbsolute(params.cwd)) {
throw RequestError.invalidParams({ cwd: params.cwd }, "`cwd` must be an absolute path");
throw RequestError.invalidParams({ cwd: params.cwd }, "cwd must be an absolute path");
}
const offset = listOffset(params.cursor);
// One more than a page tells whether a next page exists.
@@ -1378,11 +1378,11 @@ async function validatedSetup(
clientSystemPrompt(request.systemPrompt);
const { cwd } = request;
if (!path.isAbsolute(cwd)) {
throw RequestError.invalidParams({ cwd }, `\`cwd\` must be an absolute path, not ${cwd}`);
throw RequestError.invalidParams({ cwd }, `cwd must be an absolute path, not ${cwd}`);
}
const stat = await fs.stat(cwd).catch(() => undefined);
if (!stat?.isDirectory()) {
throw RequestError.invalidParams({ cwd }, `\`cwd\` is not a directory: ${cwd}`);
throw RequestError.invalidParams({ cwd }, `cwd is not a directory: ${cwd}`);
}
for (const directory of request.additionalDirectories ?? []) {
if (!path.isAbsolute(directory)) {
@@ -1416,7 +1416,7 @@ function assertCwdOf(session: V2Session, cwd: string, action: string): void {
if (cwd === session.cwd) return;
throw RequestError.invalidParams(
{ cwd },
`Session ${session.sessionId} works in ${session.cwd}: ${action} with that \`cwd\``,
`Session ${session.sessionId} works in ${session.cwd}: ${action} with that cwd`,
);
}

View File

@@ -32,7 +32,7 @@ export function v1PromptRequest({
...request
}: v2.PromptRequest): PromptRequest {
if (prompt.length === 0) {
throw RequestError.invalidParams({ prompt }, "`prompt` must hold at least one content block");
throw RequestError.invalidParams({ prompt }, "prompt must hold at least one content block");
}
return {
...request,