Keep error classes across links

Error responses now carry the registered name of the thrown error's
class, and the requester rejects with an instance of that class instead
of a generic RequestError. Error classes are registered like message
classes, and plugins list their own in `errors`.

RequestError is replaced by a hierarchy following the HTTP status codes:
ClientError (ValidationError, ForbiddenError, NotFoundError,
TimeoutError, ConflictError) and ServerError (InternalServerError).
PermissionError is PermissionDeniedError and the config errors
InvalidValue, InvalidField and InvalidAccess gain an Error suffix.

Link logs only errors whose class is not registered. These arrive on the
other side as InternalServerError with the original message and stack,
so an error forwarded through the controller is logged once, where it
was thrown.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bbassieandClaude Opus 5.5 committed 2026-10-27 22:03:13 +00:00
1 parent ffe82f81d8
commit 1c7c00b033
37 files changed
+589 -310

No files matched your search

+6 -6
View File
@@ -2,7 +2,7 @@ import util from "util";
import path from "path";
import { exec } from "child_process";
import { logger } from "./logging.js";
import { RequestError } from "./errors.js";
import { ConflictError, NotFoundError, UnavailableError } from "./errors.js";
import type { PluginNodeEnvInfo } from "./plugin.js";
import { isNonRegistryPackage } from "./load_plugin_list.js";
import { LockFile, LockFileExistsError, LockFileRecoveryError } from "./LockFile.js";
@@ -31,7 +31,7 @@ let operationInProgress = false;
async function logExec(cmd: string, check?: () => Promise<void>) {
// Checked and set before the first await so concurrent calls in this process can't interleave
if (operationInProgress) {
throw new RequestError(operationInProgressMessage);
throw new ConflictError(operationInProgressMessage);
}
operationInProgress = true;
const lockPath = path.resolve("npm-operation.lock");
@@ -43,13 +43,13 @@ async function logExec(cmd: string, check?: () => Promise<void>) {
await lock.acquire();
} catch (err) {
if (err instanceof LockFileRecoveryError) {
throw new RequestError(err.message);
throw new UnavailableError(err.message);
}
if (!(err instanceof LockFileExistsError)) {
throw err;
}
const holder = await lock.holderPid();
throw new RequestError(
throw new ConflictError(
`${operationInProgressMessage}${holder ? ` (${lockPath} is held by process ${holder})` : ""}`
);
}
@@ -90,7 +90,7 @@ export async function handleUpdateAll(corePackage: string, pluginInfos: PluginNo
/** Throws if the dependency by this name is a path, git, url or alias that installing by name would replace */
async function checkNotLocalDependency(name: string) {
if (await isNonRegistryPackage(name)) {
throw new RequestError(`${name} is not installed from npm on this machine`);
throw new ConflictError(`${name} is not installed from npm on this machine`);
}
}
@@ -98,7 +98,7 @@ export async function handlePluginUpdate(pluginName: string, pluginInfos: Plugin
// Optionally pinned to a version as name@version to update past the range in package.json
const { name, version } = parsePackageSpec(pluginName);
if (!pluginInfos.some(plugin => plugin.npmPackage === name)) {
throw new RequestError(`Plugin ${name} is not installed on this machine`);
throw new NotFoundError(`Plugin ${name} is not installed on this machine`);
}
if (version === undefined) {