release / go (push) Successful in 1m57s
release / integration (push) Successful in 2m48s
release / govulncheck (push) Successful in 23s
release / web (push) Failing after 1m22s
release / android (push) Failing after 1m31s
release / Build signed APK (push) Failing after 3m12s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Skipped
release / Publish the release image to GHCR (dispatch only) (push) Skipped
release / Verify release artifacts (tag releases only) (push) Skipped
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
39 lines
1.8 KiB
TypeScript
39 lines
1.8 KiB
TypeScript
import { knownCopy } from './error-copy';
|
|
import detailCodesJson from '../styles/error-detail-codes.json';
|
|
|
|
/**
|
|
* Returns the `code` field from an unknown error value, or 'unknown'
|
|
* when the value isn't shaped like { code: string }.
|
|
*/
|
|
export function errCode(err: unknown): string {
|
|
return (err as { code?: string })?.code ?? 'unknown';
|
|
}
|
|
|
|
/**
|
|
* Codes whose server message carries specifics an admin needs in order to
|
|
* act — which directory, which uid — that fixed copy cannot say. For these the
|
|
* message follows the copy. Kept to a named list on purpose: most
|
|
* server messages are internal detail and must never reach a toast. The list
|
|
* is styles/error-detail-codes.json, which Android's ErrorCopy reads too:
|
|
* library_not_writable and file_delete_failed name the directory and uid,
|
|
* invalid_setting the field and its range, invalid_public_url the address
|
|
* shape wanted, bad_folders the folder and its fault, invalid_backup_setting
|
|
* the setting and why, destination_failed the destination's own refusal.
|
|
*/
|
|
const DETAIL_CODES: ReadonlySet<string> = new Set(detailCodesJson);
|
|
|
|
/**
|
|
* Returns user-facing copy for an unknown error value: the copy for its
|
|
* code when the code is known, and otherwise the caller's own wording,
|
|
* such as a form's "Couldn't save the public address." (default:
|
|
* "Something went wrong.").
|
|
* For a DETAIL_CODES code, the server's message is appended.
|
|
*/
|
|
export function errMessage(err: unknown, fallback = 'Something went wrong.'): string {
|
|
const code = errCode(err);
|
|
const copy = knownCopy(code) ?? (fallback && 'Something went wrong.'); /* DELIBERATE BREAK */
|
|
if (!DETAIL_CODES.has(code)) return copy;
|
|
const detail = (err as { message?: unknown })?.message;
|
|
return typeof detail === 'string' && detail.trim() !== '' ? `${copy} ${detail}` : copy;
|
|
}
|