| author | |
| committer | |
| log | cedba8ef7133a2d55f9c5318b0e6098ab0fe4abd |
| tree | 42bf64c9720ccf837b62bf4647cc1862e0f8c950 |
| parent | a25086ee5de025766806d480542ed6c10aef35f9 |
| signature | Signed by SSH key SHA256:cOKiuRFOeSRxne6EWgHtdQQSlBxjOXm2hOCFnCdLQbQ |
found this was better namespace name while working on incremental.
closes #10510 files changed, 72 insertions(+), 72 deletions(-)
framework/font.ts+3-3| ... | @@ -97,7 +97,7 @@ async function fetchProductionFontFiles( | ... | @@ -97,7 +97,7 @@ async function fetchProductionFontFiles( |
| 97 | throw new Error(`Fetching fallback from ${url} failed: ${response.status} ${response.statusText}`); | 97 | throw new Error(`Fetching fallback from ${url} failed: ${response.status} ${response.statusText}`); |
| 98 | } | 98 | } |
| 99 | } catch (err) { | 99 | } catch (err) { |
| 100 | throw new Error(`Fetching fallback from ${url} failed: ${error.message(err)}`); | 100 | throw new Error(`Fetching fallback from ${url} failed: ${exception.message(err)}`); |
| 101 | } | 101 | } |
| 102 | } | 102 | } |
| 103 | 103 | ||
| ... | @@ -137,7 +137,7 @@ export async function fetchFont(ref: progress.Ref, name: string, sources: string | ... | @@ -137,7 +137,7 @@ export async function fetchFont(ref: progress.Ref, name: string, sources: string |
| 137 | continue; | 137 | continue; |
| 138 | } | 138 | } |
| 139 | } catch (err) { | 139 | } catch (err) { |
| 140 | errs.push(`Fetching from ${source} failed: ${error.message(err)}`); | 140 | errs.push(`Fetching from ${source} failed: ${exception.message(err)}`); |
| 141 | continue; | 141 | continue; |
| 142 | } | 142 | } |
| 143 | } | 143 | } |
| ... | @@ -386,7 +386,7 @@ import * as sg from "#sitegen"; | ... | @@ -386,7 +386,7 @@ import * as sg from "#sitegen"; |
| 386 | import * as fs from "#sitegen/fs"; | 386 | import * as fs from "#sitegen/fs"; |
| 387 | import { ASSERT } from "@clo/lib/assert"; | 387 | import { ASSERT } from "@clo/lib/assert"; |
| 388 | import * as async from "@clo/lib/async"; | 388 | import * as async from "@clo/lib/async"; |
| 389 | import * as error from "@clo/lib/error"; | 389 | import * as exception from "@clo/lib/exception"; |
| 390 | import * as progress from "@clo/lib/progress"; | 390 | import * as progress from "@clo/lib/progress"; |
| 391 | import * as queue from "@clo/lib/queue"; | 391 | import * as queue from "@clo/lib/queue"; |
| 392 | import { readFile } from "node:fs/promises"; | 392 | import { readFile } from "node:fs/promises"; |
framework/generate.ts+2-2| ... | @@ -362,7 +362,7 @@ export async function preparePage( | ... | @@ -362,7 +362,7 @@ export async function preparePage( |
| 362 | clientRefs: Array.from(cloverScripts), | 362 | clientRefs: Array.from(cloverScripts), |
| 363 | } as const; | 363 | } as const; |
| 364 | } catch (e) { | 364 | } catch (e) { |
| 365 | error.rethrowWithMetadata(e, { page: item.id }); | 365 | exception.rethrowWithMetadata(e, { page: item.id }); |
| 366 | } | 366 | } |
| 367 | } | 367 | } |
| 368 | 368 | ||
| ... | @@ -456,7 +456,7 @@ import * as path from "node:path"; | ... | @@ -456,7 +456,7 @@ import * as path from "node:path"; |
| 456 | import * as sg from "#sitegen"; | 456 | import * as sg from "#sitegen"; |
| 457 | import type { FileItem } from "#sitegen"; | 457 | import type { FileItem } from "#sitegen"; |
| 458 | import * as fs from "#sitegen/fs"; | 458 | import * as fs from "#sitegen/fs"; |
| 459 | import * as error from "@clo/lib/error"; | 459 | import * as exception from "@clo/lib/exception"; |
| 460 | import * as meta from "@clo/lib/meta"; | 460 | import * as meta from "@clo/lib/meta"; |
| 461 | import * as progress from "@clo/lib/progress"; | 461 | import * as progress from "@clo/lib/progress"; |
| 462 | 462 |
framework/lib/path.ts+3-3| ... | @@ -131,7 +131,7 @@ export class Path { | ... | @@ -131,7 +131,7 @@ export class Path { |
| 131 | try { | 131 | try { |
| 132 | return this.readSync(encoding); | 132 | return this.readSync(encoding); |
| 133 | } catch (err) { | 133 | } catch (err) { |
| 134 | if (error.code(err) === "ENOENT") return null; | 134 | if (exception.code(err) === "ENOENT") return null; |
| 135 | throw err; | 135 | throw err; |
| 136 | } | 136 | } |
| 137 | } | 137 | } |
| ... | @@ -159,7 +159,7 @@ export class Path { | ... | @@ -159,7 +159,7 @@ export class Path { |
| 159 | try { | 159 | try { |
| 160 | return await this.read(encoding); | 160 | return await this.read(encoding); |
| 161 | } catch (err) { | 161 | } catch (err) { |
| 162 | if (error.code(err) === "ENOENT") return null; | 162 | if (exception.code(err) === "ENOENT") return null; |
| 163 | throw err; | 163 | throw err; |
| 164 | } | 164 | } |
| 165 | } | 165 | } |
| ... | @@ -209,7 +209,7 @@ export class Path { | ... | @@ -209,7 +209,7 @@ export class Path { |
| 209 | } | 209 | } |
| 210 | 210 | ||
| 211 | import { ASSERT } from "@clo/lib/assert"; | 211 | import { ASSERT } from "@clo/lib/assert"; |
| 212 | import * as error from "@clo/lib/error"; | 212 | import * as exception from "@clo/lib/exception"; |
| 213 | import type { RmOptions } from "node:fs"; | 213 | import type { RmOptions } from "node:fs"; |
| 214 | import * as path from "node:path"; | 214 | import * as path from "node:path"; |
| 215 | import * as util from "node:util"; | 215 | import * as util from "node:util"; |
lib/error.ts deleted-53| ... | @@ -1,53 +0,0 @@ | ||
| 1 | /** | ||
| 2 | * helper functions for dealing with the `unknown` type, mainly in `catch` | ||
| 3 | * blocks or promise rejection callbacks. | ||
| 4 | * | ||
| 5 | * @module | ||
| 6 | */ | ||
| 7 | |||
| 8 | /** extra fields on errors are extremely helpful for debugging. */ | ||
| 9 | export interface Error extends globalThis.Error { | ||
| 10 | [metadata: string]: unknown; | ||
| 11 | } | ||
| 12 | |||
| 13 | /** retrieve an error message from any value */ | ||
| 14 | export function message(error: unknown): string { | ||
| 15 | let message = (error as { message: unknown })?.message ?? error; | ||
| 16 | try { | ||
| 17 | message = typeof message === "string" | ||
| 18 | ? message | ||
| 19 | // NOTE: typescript standard library lies here (https://github.com/mattpocock/ts-reset/pull/190) | ||
| 20 | : String(JSON.stringify(message) as string | undefined); | ||
| 21 | } catch {} | ||
| 22 | try { | ||
| 23 | return String(message); | ||
| 24 | } catch {} | ||
| 25 | return `Could not stringify error message ${typeof message}`; | ||
| 26 | } | ||
| 27 | |||
| 28 | /** retrieve an error-like object from any value. Useful to check fields. */ | ||
| 29 | export function obj(error: unknown): { message: string } & Partial<Error> { | ||
| 30 | if (error instanceof Error) return error as Error; | ||
| 31 | return { | ||
| 32 | message: message(error), | ||
| 33 | ...(typeof error === "object" && error), | ||
| 34 | }; | ||
| 35 | } | ||
| 36 | |||
| 37 | /** node.js error codes are string values on the `.code` property. */ | ||
| 38 | export function code(error: unknown): node.ErrorCode | null { | ||
| 39 | const code = (error as { code: unknown })?.code; | ||
| 40 | return typeof code === "string" ? code : null; | ||
| 41 | } | ||
| 42 | |||
| 43 | /** attach extra fields and rethrow a value. */ | ||
| 44 | export function rethrowWithMetadata( | ||
| 45 | err: unknown, | ||
| 46 | meta: Record<string, unknown>, | ||
| 47 | ): never { | ||
| 48 | const error = err && typeof err === "object" ? err : new Error(message(err)); // no stack trace :/ | ||
| 49 | Object.assign(error, meta); | ||
| 50 | throw error; | ||
| 51 | } | ||
| 52 | |||
| 53 | import type * as node from "./node.ts"; | ||
lib/exception.ts created+53| ... | @@ -0,0 +1,53 @@ | ||
| 1 | /** | ||
| 2 | * helper functions for dealing with the `unknown` type, mainly in `catch` | ||
| 3 | * blocks or promise rejection callbacks. | ||
| 4 | * | ||
| 5 | * @module | ||
| 6 | */ | ||
| 7 | |||
| 8 | /** extra fields on errors are extremely helpful for debugging. */ | ||
| 9 | export interface Error extends globalThis.Error { | ||
| 10 | [metadata: string]: unknown; | ||
| 11 | } | ||
| 12 | |||
| 13 | /** retrieve an error message from any value */ | ||
| 14 | export function message(error: unknown): string { | ||
| 15 | let message = (error as { message: unknown })?.message ?? error; | ||
| 16 | try { | ||
| 17 | message = typeof message === "string" | ||
| 18 | ? message | ||
| 19 | // NOTE: typescript standard library lies here (https://github.com/mattpocock/ts-reset/pull/190) | ||
| 20 | : String(JSON.stringify(message) as string | undefined); | ||
| 21 | } catch {} | ||
| 22 | try { | ||
| 23 | return String(message); | ||
| 24 | } catch {} | ||
| 25 | return `Could not stringify error message ${typeof message}`; | ||
| 26 | } | ||
| 27 | |||
| 28 | /** retrieve an error-like object from any value. Useful to check fields. */ | ||
| 29 | export function obj(error: unknown): { message: string } & Partial<Error> { | ||
| 30 | if (error instanceof Error) return error as Error; | ||
| 31 | return { | ||
| 32 | message: message(error), | ||
| 33 | ...(typeof error === "object" && error), | ||
| 34 | }; | ||
| 35 | } | ||
| 36 | |||
| 37 | /** node.js error codes are string values on the `.code` property. */ | ||
| 38 | export function code(error: unknown): node.ErrorCode | null { | ||
| 39 | const code = (error as { code: unknown })?.code; | ||
| 40 | return typeof code === "string" ? code : null; | ||
| 41 | } | ||
| 42 | |||
| 43 | /** attach extra fields and rethrow a value. */ | ||
| 44 | export function rethrowWithMetadata( | ||
| 45 | err: unknown, | ||
| 46 | meta: Record<string, unknown>, | ||
| 47 | ): never { | ||
| 48 | const error = err && typeof err === "object" ? err : new Error(message(err)); // no stack trace :/ | ||
| 49 | Object.assign(error, meta); | ||
| 50 | throw error; | ||
| 51 | } | ||
| 52 | |||
| 53 | import type * as node from "./node.ts"; | ||
lib/http.ts+2-2| ... | @@ -82,7 +82,7 @@ export async function serve( | ... | @@ -82,7 +82,7 @@ export async function serve( |
| 82 | 82 | ||
| 83 | const actualPort = await new Promise<number>((resolve, reject) => { | 83 | const actualPort = await new Promise<number>((resolve, reject) => { |
| 84 | async function onError(err: unknown) { | 84 | async function onError(err: unknown) { |
| 85 | if (error.code(err) !== "EADDRINUSE") { | 85 | if (exception.code(err) !== "EADDRINUSE") { |
| 86 | reject(err); | 86 | reject(err); |
| 87 | return; | 87 | return; |
| 88 | } | 88 | } |
| ... | @@ -168,7 +168,7 @@ export interface Range { | ... | @@ -168,7 +168,7 @@ export interface Range { |
| 168 | import * as nodeHttp from "node:http"; | 168 | import * as nodeHttp from "node:http"; |
| 169 | import * as stream from "node:stream"; | 169 | import * as stream from "node:stream"; |
| 170 | import { ASSERT, UNWRAP } from "./assert.ts"; | 170 | import { ASSERT, UNWRAP } from "./assert.ts"; |
| 171 | import * as error from "./error.ts"; | 171 | import * as exception from "./exception.ts"; |
| 172 | import * as node from "./node.ts"; | 172 | import * as node from "./node.ts"; |
| 173 | import * as progress from "./progress.ts"; | 173 | import * as progress from "./progress.ts"; |
| 174 | import * as subprocess from "./subprocess.ts"; | 174 | import * as subprocess from "./subprocess.ts"; |
lib/log.ts+2-2| ... | @@ -603,7 +603,7 @@ export function createTerminalWidgetHost( | ... | @@ -603,7 +603,7 @@ export function createTerminalWidgetHost( |
| 603 | height: rows, | 603 | height: rows, |
| 604 | }); | 604 | }); |
| 605 | } catch (e) { | 605 | } catch (e) { |
| 606 | out = e instanceof Error ? stack.format(e, color) : errors.message(e); | 606 | out = e instanceof Error ? stack.format(e, color) : exceptions.message(e); |
| 607 | } | 607 | } |
| 608 | if (out == null) { | 608 | if (out == null) { |
| 609 | widgets.splice(w, 1); | 609 | widgets.splice(w, 1); |
| ... | @@ -1509,7 +1509,7 @@ export type MessageFormatFunction = ( | ... | @@ -1509,7 +1509,7 @@ export type MessageFormatFunction = ( |
| 1509 | 1509 | ||
| 1510 | import { ASSERT, UNWRAP } from "./assert.ts"; | 1510 | import { ASSERT, UNWRAP } from "./assert.ts"; |
| 1511 | import * as async from "./async.ts"; | 1511 | import * as async from "./async.ts"; |
| 1512 | import * as errors from "./error.ts"; | 1512 | import * as exceptions from "./exception.ts"; |
| 1513 | import * as stack from "./log/stack.ts"; | 1513 | import * as stack from "./log/stack.ts"; |
| 1514 | import * as node from "./node.ts"; | 1514 | import * as node from "./node.ts"; |
| 1515 | import * as ansi from "./string/ansi.ts"; | 1515 | import * as ansi from "./string/ansi.ts"; |
lib/progress.ts+2-2| ... | @@ -987,7 +987,7 @@ export function encodeEventStream< | ... | @@ -987,7 +987,7 @@ export function encodeEventStream< |
| 987 | emitNow(); | 987 | emitNow(); |
| 988 | })); | 988 | })); |
| 989 | stack.use(root.on("error", (error) => { | 989 | stack.use(root.on("error", (error) => { |
| 990 | s.pendingEvents.push(["error", errors.message(error)]); | 990 | s.pendingEvents.push(["error", exceptions.message(error)]); |
| 991 | s.ended = true; | 991 | s.ended = true; |
| 992 | emitNow(); | 992 | emitNow(); |
| 993 | })); | 993 | })); |
| ... | @@ -1857,7 +1857,7 @@ export const internals: { | ... | @@ -1857,7 +1857,7 @@ export const internals: { |
| 1857 | import { ASSERT, UNWRAP } from "./assert.ts"; | 1857 | import { ASSERT, UNWRAP } from "./assert.ts"; |
| 1858 | import * as async from "./async.ts"; | 1858 | import * as async from "./async.ts"; |
| 1859 | import * as bytes from "./bytes.ts"; | 1859 | import * as bytes from "./bytes.ts"; |
| 1860 | import * as errors from "./error.ts"; | 1860 | import * as exceptions from "./exception.ts"; |
| 1861 | import { Events } from "./Events.ts"; | 1861 | import { Events } from "./Events.ts"; |
| 1862 | import * as log from "./log.ts"; | 1862 | import * as log from "./log.ts"; |
| 1863 | import * as stack from "./log/stack.ts"; | 1863 | import * as stack from "./log/stack.ts"; |
src/file-viewer/cache.ts+2-2| ... | @@ -127,7 +127,7 @@ export async function read( | ... | @@ -127,7 +127,7 @@ export async function read( |
| 127 | try { | 127 | try { |
| 128 | ({ size } = await localFile.stat()); | 128 | ({ size } = await localFile.stat()); |
| 129 | } catch (err) { | 129 | } catch (err) { |
| 130 | if (error.code(err) === "ENOENT") { | 130 | if (exception.code(err) === "ENOENT") { |
| 131 | console.warn(`missing local file: ${localFile}`); | 131 | console.warn(`missing local file: ${localFile}`); |
| 132 | break local; | 132 | break local; |
| 133 | } | 133 | } |
| ... | @@ -598,7 +598,7 @@ import * as fs from "#sitegen/fs"; | ... | @@ -598,7 +598,7 @@ import * as fs from "#sitegen/fs"; |
| 598 | import { Path } from "#sitegen/path"; | 598 | import { Path } from "#sitegen/path"; |
| 599 | import { ASSERT, UNWRAP } from "@clo/lib/assert"; | 599 | import { ASSERT, UNWRAP } from "@clo/lib/assert"; |
| 600 | import * as async from "@clo/lib/async"; | 600 | import * as async from "@clo/lib/async"; |
| 601 | import * as error from "@clo/lib/error"; | 601 | import * as exception from "@clo/lib/exception"; |
| 602 | import * as log from "@clo/lib/log"; | 602 | import * as log from "@clo/lib/log"; |
| 603 | import { Lru } from "@clo/lib/Lru"; | 603 | import { Lru } from "@clo/lib/Lru"; |
| 604 | import * as ts from "@clo/lib/ts"; | 604 | import * as ts from "@clo/lib/ts"; |
src/file-viewer/indexer/scan.ts+3-3| ... | @@ -125,7 +125,7 @@ export class Scanner { | ... | @@ -125,7 +125,7 @@ export class Scanner { |
| 125 | try { | 125 | try { |
| 126 | stat = await path.stat(); | 126 | stat = await path.stat(); |
| 127 | } catch (err) { | 127 | } catch (err) { |
| 128 | if (error.code(err) !== "ENOENT") throw err; | 128 | if (exception.code(err) !== "ENOENT") throw err; |
| 129 | // deleted; watcher events often describe files already gone | 129 | // deleted; watcher events often describe files already gone |
| 130 | this.#removePath(publicPath); | 130 | this.#removePath(publicPath); |
| 131 | return; | 131 | return; |
| ... | @@ -308,7 +308,7 @@ export class Scanner { | ... | @@ -308,7 +308,7 @@ export class Scanner { |
| 308 | try { | 308 | try { |
| 309 | stat = await path.stat(); | 309 | stat = await path.stat(); |
| 310 | } catch (err) { | 310 | } catch (err) { |
| 311 | if (error.code(err) === "ENOENT") return null; | 311 | if (exception.code(err) === "ENOENT") return null; |
| 312 | throw err; | 312 | throw err; |
| 313 | } | 313 | } |
| 314 | } | 314 | } |
| ... | @@ -546,7 +546,7 @@ import * as path from "node:path"; | ... | @@ -546,7 +546,7 @@ import * as path from "node:path"; |
| 546 | import { Path } from "#sitegen/path"; | 546 | import { Path } from "#sitegen/path"; |
| 547 | import { ASSERT, UNWRAP } from "@clo/lib/assert"; | 547 | import { ASSERT, UNWRAP } from "@clo/lib/assert"; |
| 548 | import * as async from "@clo/lib/async"; | 548 | import * as async from "@clo/lib/async"; |
| 549 | import * as error from "@clo/lib/error"; | 549 | import * as exception from "@clo/lib/exception"; |
| 550 | import * as log from "@clo/lib/log"; | 550 | import * as log from "@clo/lib/log"; |
| 551 | import * as progress from "@clo/lib/progress"; | 551 | import * as progress from "@clo/lib/progress"; |
| 552 | import * as queue from "@clo/lib/queue"; | 552 | import * as queue from "@clo/lib/queue"; |