From 71150900ffd9df35bfcc6c4ac461aeeaf69b249c Mon Sep 17 00:00:00 2001 From: Danny Kim Date: Mon, 19 Oct 2026 19:45:02 +0900 Subject: [PATCH] Turn on custom-error-definition and name the custom errors --- scripts/project-lint.ts | 3 --- src/post/post.ts | 7 ++++++- src/profiles/profiles.ts | 7 ++++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/scripts/project-lint.ts b/scripts/project-lint.ts index 1c4b886..08d0723 100644 --- a/scripts/project-lint.ts +++ b/scripts/project-lint.ts @@ -260,9 +260,6 @@ const rules: DummyRuleMap = { // PENDING USER: union members are values in profiles.json, the Gitea API, // and posted comments; renaming them changes behavior. "explicit-types/upper-snake-string-unions": "off", - // PENDING USER: a fitting `name` needs a constructor and changes logged - // error names. - "unicorn/custom-error-definition": "off", // Off, too much churn: // Literal numbers read better than a constant per use. "no-magic-numbers": "off", diff --git a/src/post/post.ts b/src/post/post.ts index f072e04..511c9ac 100644 --- a/src/post/post.ts +++ b/src/post/post.ts @@ -36,7 +36,12 @@ const failureComment = (failures: ProfileFailure[]): string => // The `fetch` subset the reviewer posts through, which tests replace. export type Fetcher = (url: string, init: RequestInit) => Promise; -class GiteaRequestError extends Error {} +class GiteaRequestError extends Error { + constructor(message: string, options?: ErrorOptions) { + super(message, options); + this.name = "GiteaRequestError"; + } +} function parseAnchors(text: string, sourcePath: string): Anchor[] { const entries: unknown = JSON.parse(text); diff --git a/src/profiles/profiles.ts b/src/profiles/profiles.ts index 90fd3fe..48edcd0 100644 --- a/src/profiles/profiles.ts +++ b/src/profiles/profiles.ts @@ -29,7 +29,12 @@ interface ProfileHome { } // Raised once an agent's credentials are rejected and any re-login is spent. -export class AgentAuthError extends Error {} +export class AgentAuthError extends Error { + constructor(message: string, options?: ErrorOptions) { + super(message, options); + this.name = "AgentAuthError"; + } +} function isUsageExhausted(error: unknown): boolean { return /(?:usage|rate) limit|hit your (?:weekly )?limit|insufficient_quota|exceeded your current quota|too many requests|(?:api error|http error|http|status(?: code)?)[ :]+4(?:02|29)\b/iu.test(