Files
opencli/src/errors.ts
T
jackwener 68840fc85c refactor: P0 architecture improvements
- Split browser.ts (700 lines) into src/browser/ module (page, mcp, errors, discover, tabs, index)
- Add unified error handling: CliError base class + logger module
- Enable TypeScript strict mode, fix 12 type errors
- Extract inline build scripts to scripts/clean-yaml.cjs and copy-yaml.cjs
- All 178 unit tests pass, build produces 83 entries across 19 sites
2026-03-17 17:01:51 +08:00

49 lines
1.3 KiB
TypeScript

/**
* Unified error types for opencli.
*
* All errors thrown by the framework should extend CliError so that
* the top-level handler in main.ts can render consistent, helpful output.
*/
export class CliError extends Error {
/** Machine-readable error code (e.g. 'BROWSER_CONNECT', 'ADAPTER_LOAD') */
readonly code: string;
/** Human-readable hint on how to fix the problem */
readonly hint?: string;
constructor(code: string, message: string, hint?: string) {
super(message);
this.name = 'CliError';
this.code = code;
this.hint = hint;
}
}
export class BrowserConnectError extends CliError {
constructor(message: string, hint?: string) {
super('BROWSER_CONNECT', message, hint);
this.name = 'BrowserConnectError';
}
}
export class AdapterLoadError extends CliError {
constructor(message: string, hint?: string) {
super('ADAPTER_LOAD', message, hint);
this.name = 'AdapterLoadError';
}
}
export class CommandExecutionError extends CliError {
constructor(message: string, hint?: string) {
super('COMMAND_EXEC', message, hint);
this.name = 'CommandExecutionError';
}
}
export class ConfigError extends CliError {
constructor(message: string, hint?: string) {
super('CONFIG', message, hint);
this.name = 'ConfigError';
}
}