Skip to the content

Capsid menu

app/lib/carrel/errors.server.ts

30 lines and 3 functions in DrDustinEdwards/dustinedwards-info, at commit 1590ba4 on 2026-10-24. This file on GitHub.

Functions

The functions of errors.server.ts
FunctionLinesComplexityCoveredCRAPMutation
constructor11 to 151No data: no coverage report in this mapNo data: no coverage report in this mapNo data: no mutants in this code
asSiteApiError22 to 347No data: no coverage report in this mapNo data: no coverage report in this mapNo data: no mutants in this code
<anonymous:30>30 to 301No data: no coverage report in this mapNo data: no coverage report in this mapNo data: no mutants in this code

Imports

It imports app/lib/editor/github.server.ts, app/lib/editor/publish.server.ts. Imported by app/kb/editor.server.ts, app/kb/procedures/save.server.ts, app/kb/registry/save.server.ts, app/lib/carrel/cv-handler.server.ts, app/lib/carrel/dictionary-handler.server.ts, app/lib/carrel/document-handler.server.ts, app/lib/carrel/page-handler.server.ts, app/lib/carrel/phage-handler.server.ts, app/lib/carrel/procedure-handler.server.ts, app/lib/carrel/publication-handler.server.ts, app/lib/carrel/registry-handler.server.ts, app/lib/carrel/roster-handler.server.ts, app/lib/carrel/site-adapter.server.ts, app/lib/cv/save.server.ts, app/lib/dictionary/save.server.ts, app/lib/llms/save.server.ts, app/lib/pages/save.server.ts, app/lib/phages/save.server.ts, app/lib/publications/save.server.ts, app/lib/roster/save.server.ts.

Source

// The site's refusals, in the package's terms, for every kind handler.

import { RefusedError, VersionConflictError } from "@dustinedwards/site-api";

import { readFile } from "~/lib/editor/github.server";
import { EditorError, GitHubError, PolicyError } from "~/lib/editor/publish.server";

/** A file the site's own validator refused, with every message so the writer can fix all of them at once. */
export class ContentInvalid extends Error {
  errors: string[];
  constructor(message: string, errors: string[]) {
    super(message);
    this.name = "ContentInvalid";
    this.errors = errors;
  }
}

/**
 * The site's refusals, in the package's terms. Anything else is a failure and stays one. `path` is the item's
 * file: a version conflict answers that file's current blob sha, which is the version the next save must carry.
 */
export async function asSiteApiError(env: Env & { GITHUB_TOKEN?: string }, error: unknown, path: string): Promise<never> {
  if (error instanceof GitHubError && error.conflict) {
    throw new VersionConflictError((await readFile(env, path))?.sha ?? null);
  }
  if (error instanceof EditorError || error instanceof PolicyError) {
    throw new RefusedError(error.message);
  }
  if (error instanceof ContentInvalid) {
    const lines = error.errors.map((message) => `- ${message}`);
    throw new RefusedError([error.message, ...lines].join("\n"));
  }
  throw error;
}