Migrate libs/aapp, arts/aapp and arts/auth errors to CodeError

Three small error catalogs converted to the canonical CodeError + ErrCode
system:
- libs/aapp: AappBusNoContextError, AappInvalidEventRuntimeError,
  AappUnsafeEventPayloadError. Adds AAPP_ERR seed plus the bus/event
  hierarchy (`aapp::bus.no_context`, `aapp::event.invalid_runtime`,
  `aapp::event.unsafe_payload`).
- arts/aapp: AappAlreadyCreatedError. Reuses libs/aapp's AAPP_ERR seed
  and adds AAPP_ERR_ALREADY_CREATED.
- arts/auth: AuthRequestFailedError, AuthDisposedError,
  AuthInvalidResponseError. Defines AUTH_ERR seed locally; once
  libs/auth migrates the seed converges (same module name, same
  `'auth::'` prefix, no conflict).

The legacy `AAPP_*_ERROR_NAME_*` and `AUTH_ERROR_NAME_*` constants are
removed — the error name now derives from the code, matching the
pattern in buss/conn/sess/perm/cach/sium/lang/timr.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
master
dev 5 months ago
parent 22058e4370
commit 834775099e

@ -1,5 +1,6 @@
export { AAPP_MODULE } from '$libs/aapp/consts';
import { AAPP_MODULE } from '$libs/aapp/consts';
import { AAPP_ERR, AAPP_MODULE } from '$libs/aapp/consts';
import { errCode, type ErrCode } from '$libs/errs';
export const AAPP_LOG_MSG_SESSION_CACHE_CLEAR_FAILED =
'session change cache clear failed';
@ -13,7 +14,7 @@ export const AAPP_ORCHESTRATION_TRANSLATOR_TENANT_SWITCHED = 'tenant-switched';
export const AAPP_ORCHESTRATION_TRANSLATOR_CONNECTIVITY = 'connectivity';
export const AAPP_ORCHESTRATION_TRANSLATOR_DISPOSE = 'dispose';
export const AAPP_ERROR_NAME_ALREADY_CREATED = 'AappAlreadyCreatedError';
export const AAPP_ERR_ALREADY_CREATED: ErrCode = errCode(AAPP_ERR, 'already_created');
export const AAPP_ERROR_ALREADY_CREATED_SESSION =
`[${AAPP_MODULE}] App.createActiveSession() called twice — only one session per App.`;

@ -1,7 +1,10 @@
import { AAPP_ERROR_NAME_ALREADY_CREATED } from './consts.ts';
import { CodeError } from '$libs/errs';
import { AAPP_ERR_ALREADY_CREATED } from './consts.ts';
export class AappAlreadyCreatedError extends Error {
override readonly name = AAPP_ERROR_NAME_ALREADY_CREATED;
export class AappAlreadyCreatedError extends CodeError {
constructor(message: string) {
super(AAPP_ERR_ALREADY_CREATED, { message });
}
}
export function isAappAlreadyCreatedError(error: unknown): error is AappAlreadyCreatedError {

@ -12,8 +12,22 @@ export {
AUTH_STORAGE_KEYS
} from '$libs/auth/consts';
import { errCode, moduleSeed, type ErrCode, type ModuleSeed } from '$libs/errs';
export const AUTH_MODULE = 'auth';
// ── Error codes ────────────────────────────────────────────────────────
//
// These cover the active client surface only. `libs/auth/errors.ts` keeps
// its own `AuthError` hierarchy with `AUTH_ERROR_CODES` for now; once that
// migrates the seed below converges with the libs definition (same module
// name, same `'auth::'` prefix, no conflict).
export const AUTH_ERR: ModuleSeed = moduleSeed(AUTH_MODULE);
export const AUTH_ERR_REQUEST_FAILED: ErrCode = errCode(AUTH_ERR, 'request_failed');
export const AUTH_ERR_DISPOSED: ErrCode = errCode(AUTH_ERR, 'disposed');
export const AUTH_ERR_INVALID_RESPONSE: ErrCode = errCode(AUTH_ERR, 'invalid_response');
export const AUTH_CLIENT_DIAGNOSTIC_EVENTS = {
OPERATION_FAILED: 'auth.client.operation_failed',
CACH_INVALIDATION_FAILED: 'auth.client.cache_invalidation_failed'
@ -40,10 +54,6 @@ export const AUTH_METHOD_REVOKE_DEVICE = 'auth.revokeDevice';
export const AUTH_METHOD_CLEAR_ERROR = 'auth.clearError';
export const AUTH_METHOD_ON_CHANGE = 'auth.onChange';
export const AUTH_ERROR_NAME_REQUEST_FAILED = 'AuthRequestFailedError';
export const AUTH_ERROR_NAME_DISPOSED = 'AuthDisposedError';
export const AUTH_ERROR_NAME_INVALID_RESPONSE = 'AuthInvalidResponseError';
export const AUTH_ERROR_MSG_REQUEST_FAILED_PREFIX = 'Authentication request failed: ';
export const AUTH_ERROR_MSG_RESPONSE_NOT_JSON = 'Authentication response is not valid JSON';
export const AUTH_ERROR_MSG_DISPOSED_SUFFIX = '() called on a disposed auth client';

@ -1,15 +1,15 @@
import { CodeError } from '$libs/errs';
import {
AUTH_ERR_DISPOSED,
AUTH_ERR_INVALID_RESPONSE,
AUTH_ERR_REQUEST_FAILED,
AUTH_ERROR_MSG_DISPOSED_SUFFIX,
AUTH_ERROR_MSG_INVALID_RESPONSE_PREFIX,
AUTH_ERROR_MSG_REQUEST_FAILED_PREFIX,
AUTH_ERROR_NAME_DISPOSED,
AUTH_ERROR_NAME_INVALID_RESPONSE,
AUTH_ERROR_NAME_REQUEST_FAILED
AUTH_ERROR_MSG_REQUEST_FAILED_PREFIX
} from './consts.ts';
import type { AuthClientSafeError } from '$libs/auth/types';
export class AuthRequestFailedError extends Error {
override readonly name = AUTH_ERROR_NAME_REQUEST_FAILED;
export class AuthRequestFailedError extends CodeError {
override readonly cause?: unknown;
constructor(
@ -20,24 +20,27 @@ export class AuthRequestFailedError extends Error {
readonly responseBody?: unknown,
cause?: unknown
) {
super(`${AUTH_ERROR_MSG_REQUEST_FAILED_PREFIX}${status} ${statusText}`.trim());
super(AUTH_ERR_REQUEST_FAILED, {
message: `${AUTH_ERROR_MSG_REQUEST_FAILED_PREFIX}${status} ${statusText}`.trim(),
cause
});
this.cause = cause;
}
}
export class AuthDisposedError extends Error {
override readonly name = AUTH_ERROR_NAME_DISPOSED;
export class AuthDisposedError extends CodeError {
constructor(method: string) {
super(`${method}${AUTH_ERROR_MSG_DISPOSED_SUFFIX}`);
super(AUTH_ERR_DISPOSED, {
message: `${method}${AUTH_ERROR_MSG_DISPOSED_SUFFIX}`
});
}
}
export class AuthInvalidResponseError extends Error {
override readonly name = AUTH_ERROR_NAME_INVALID_RESPONSE;
export class AuthInvalidResponseError extends CodeError {
constructor(readonly method: string) {
super(`${AUTH_ERROR_MSG_INVALID_RESPONSE_PREFIX}${method}`);
super(AUTH_ERR_INVALID_RESPONSE, {
message: `${AUTH_ERROR_MSG_INVALID_RESPONSE_PREFIX}${method}`
});
}
}

@ -8,14 +8,15 @@ export {
AUTH_CLIENT_LOG_MESSAGE_CACHE_INVALIDATION_FAILED,
AUTH_CLIENT_LOG_MESSAGE_OPERATION_FAILED,
AUTH_COOKIE_NAMES,
AUTH_ERR,
AUTH_ERR_DISPOSED,
AUTH_ERR_INVALID_RESPONSE,
AUTH_ERR_REQUEST_FAILED,
AUTH_ERROR_CODES,
AUTH_ERROR_MSG_DISPOSED_SUFFIX,
AUTH_ERROR_MSG_INVALID_RESPONSE_PREFIX,
AUTH_ERROR_MSG_REQUEST_FAILED_PREFIX,
AUTH_ERROR_MSG_RESPONSE_NOT_JSON,
AUTH_ERROR_NAME_DISPOSED,
AUTH_ERROR_NAME_INVALID_RESPONSE,
AUTH_ERROR_NAME_REQUEST_FAILED,
AUTH_HEADER_NAMES,
AUTH_HTTP_METHODS,
AUTH_HTTP_STATUS,

@ -1,16 +1,23 @@
/**
* Generic constants for `libs/aapp`. Public app-event names and payload
* types live in `./events.ts`; constants here are framework-internal
* (context keys, error names, runtime gates).
* (context keys, error codes, runtime gates).
*/
import { errCode, moduleSeed, type ErrCode, type ModuleSeed } from '$libs/errs';
export const AAPP_MODULE = 'aapp';
export const AAPP_BUS_CONTEXT_KEY = 'libs.aapp.bus';
export const AAPP_BUS_ERROR_NAME_NO_CONTEXT = 'AappBusNoContextError';
export const AAPP_EVENT_ERROR_NAME_INVALID_RUNTIME = 'AappInvalidEventRuntimeError';
export const AAPP_EVENT_ERROR_NAME_UNSAFE_PAYLOAD = 'AappUnsafeEventPayloadError';
// ── Error codes ────────────────────────────────────────────────────────
export const AAPP_ERR: ModuleSeed = moduleSeed(AAPP_MODULE);
export const AAPP_ERR_BUS: ErrCode = errCode(AAPP_ERR, 'bus');
export const AAPP_ERR_BUS_NO_CONTEXT: ErrCode = errCode(AAPP_ERR_BUS, 'no_context');
export const AAPP_ERR_EVENT: ErrCode = errCode(AAPP_ERR, 'event');
export const AAPP_ERR_EVENT_INVALID_RUNTIME: ErrCode = errCode(AAPP_ERR_EVENT, 'invalid_runtime');
export const AAPP_ERR_EVENT_UNSAFE_PAYLOAD: ErrCode = errCode(AAPP_ERR_EVENT, 'unsafe_payload');
export const AAPP_BUS_ERROR_MSG_NO_CONTEXT =
`[${AAPP_MODULE}] no bus in context — call setBus(App.Bus) in a layout before getBus()`;

@ -1,42 +1,42 @@
import { CodeError } from '$libs/errs';
import {
AAPP_BUS_ERROR_MSG_NO_CONTEXT,
AAPP_BUS_ERROR_NAME_NO_CONTEXT,
AAPP_ERR_BUS_NO_CONTEXT,
AAPP_ERR_EVENT_INVALID_RUNTIME,
AAPP_ERR_EVENT_UNSAFE_PAYLOAD,
AAPP_EVENT_ERROR_MSG_INVALID_RUNTIME,
AAPP_EVENT_ERROR_MSG_UNSAFE_PAYLOAD,
AAPP_EVENT_ERROR_NAME_INVALID_RUNTIME,
AAPP_EVENT_ERROR_NAME_UNSAFE_PAYLOAD
AAPP_EVENT_ERROR_MSG_UNSAFE_PAYLOAD
} from './consts.ts';
export class AappBusNoContextError extends Error {
export class AappBusNoContextError extends CodeError {
constructor(message = AAPP_BUS_ERROR_MSG_NO_CONTEXT) {
super(message);
this.name = AAPP_BUS_ERROR_NAME_NO_CONTEXT;
super(AAPP_ERR_BUS_NO_CONTEXT, { message });
}
}
export class AappInvalidEventRuntimeError extends Error {
export class AappInvalidEventRuntimeError extends CodeError {
readonly type: string;
readonly allowed: string;
readonly where: string;
constructor(type: string, allowed: string, where: string) {
super(
`${AAPP_EVENT_ERROR_MSG_INVALID_RUNTIME} (type=${type}, allowed=${allowed}, where=${where})`
);
this.name = AAPP_EVENT_ERROR_NAME_INVALID_RUNTIME;
super(AAPP_ERR_EVENT_INVALID_RUNTIME, {
message: `${AAPP_EVENT_ERROR_MSG_INVALID_RUNTIME} (type=${type}, allowed=${allowed}, where=${where})`
});
this.type = type;
this.allowed = allowed;
this.where = where;
}
}
export class AappUnsafeEventPayloadError extends Error {
export class AappUnsafeEventPayloadError extends CodeError {
readonly type: string;
readonly path: string;
constructor(type: string, path: string) {
super(`${AAPP_EVENT_ERROR_MSG_UNSAFE_PAYLOAD} (type=${type}, path=${path})`);
this.name = AAPP_EVENT_ERROR_NAME_UNSAFE_PAYLOAD;
super(AAPP_ERR_EVENT_UNSAFE_PAYLOAD, {
message: `${AAPP_EVENT_ERROR_MSG_UNSAFE_PAYLOAD} (type=${type}, path=${path})`
});
this.type = type;
this.path = path;
}

Loading…
Cancel
Save

Powered by TurnKey Linux.