@genfeedai/errors 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # @genfeedai/errors
2
+
3
+ Shared terminal-friendly error primitives for Genfeed CLIs.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm i @genfeedai/errors
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import { ApiError, formatError, handleError } from '@genfeedai/errors';
15
+
16
+ try {
17
+ throw new ApiError('Request failed', 500, 'Retry in a few seconds');
18
+ } catch (err) {
19
+ console.error(formatError(err));
20
+ handleError(err);
21
+ }
22
+ ```
23
+
24
+ ## Related Packages
25
+
26
+ - `@genfeedai/cli`
27
+ - `@genfeedai/skills-pro`
28
+
29
+ ## Build Faster with Genfeed
30
+
31
+ Ship consistent CLI error handling or run everything in Genfeed at [https://genfeed.ai](https://genfeed.ai).
32
+
33
+ ## License
34
+
35
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,51 @@
1
+ 'use strict';
2
+
3
+ var chalk = require('chalk');
4
+
5
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
6
+
7
+ var chalk__default = /*#__PURE__*/_interopDefault(chalk);
8
+
9
+ // src/index.ts
10
+ var BaseCliError = class extends Error {
11
+ suggestion;
12
+ constructor(message, suggestion) {
13
+ super(message);
14
+ this.name = "BaseCliError";
15
+ this.suggestion = suggestion;
16
+ }
17
+ };
18
+ var ApiError = class extends BaseCliError {
19
+ statusCode;
20
+ constructor(message, statusCode, suggestion) {
21
+ super(message, suggestion);
22
+ this.name = "ApiError";
23
+ this.statusCode = statusCode;
24
+ }
25
+ };
26
+ function formatError(error) {
27
+ if (error instanceof BaseCliError) {
28
+ let output = chalk__default.default.red(`\u2716 ${error.message}`);
29
+ if (error.suggestion) {
30
+ output += `
31
+ ${chalk__default.default.dim(error.suggestion)}`;
32
+ }
33
+ return output;
34
+ }
35
+ if (error instanceof Error) {
36
+ return chalk__default.default.red(`\u2716 ${error.message}`);
37
+ }
38
+ return chalk__default.default.red("\u2716 An unknown error occurred");
39
+ }
40
+ function handleError(error, options) {
41
+ console.error(formatError(error));
42
+ if (options?.replMode) {
43
+ throw error;
44
+ }
45
+ process.exit(1);
46
+ }
47
+
48
+ exports.ApiError = ApiError;
49
+ exports.BaseCliError = BaseCliError;
50
+ exports.formatError = formatError;
51
+ exports.handleError = handleError;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Base error class for all Genfeed CLI tools.
3
+ * Provides an optional `suggestion` field for actionable user guidance.
4
+ *
5
+ * Domain-specific repos extend this:
6
+ * - CLI: `GenfeedError extends BaseCliError`
7
+ * - Skills-Pro: `SkillsProError extends BaseCliError`
8
+ */
9
+ declare class BaseCliError extends Error {
10
+ suggestion?: string;
11
+ constructor(message: string, suggestion?: string);
12
+ }
13
+ /**
14
+ * Shared API error with HTTP status code.
15
+ * Used identically by CLI and skills-pro for HTTP client errors.
16
+ */
17
+ declare class ApiError extends BaseCliError {
18
+ statusCode?: number;
19
+ constructor(message: string, statusCode?: number, suggestion?: string);
20
+ }
21
+ /**
22
+ * Format an error for terminal display.
23
+ * Handles BaseCliError (with suggestion), generic Error, and unknown errors.
24
+ */
25
+ declare function formatError(error: unknown): string;
26
+ interface HandleErrorOptions {
27
+ /** When true, re-throws the error instead of exiting (for REPL mode). */
28
+ replMode?: boolean;
29
+ }
30
+ /**
31
+ * Print a formatted error and exit the process.
32
+ * Supports REPL mode where errors are re-thrown instead of calling process.exit.
33
+ */
34
+ declare function handleError(error: unknown, options?: HandleErrorOptions): never;
35
+
36
+ export { ApiError, BaseCliError, type HandleErrorOptions, formatError, handleError };
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Base error class for all Genfeed CLI tools.
3
+ * Provides an optional `suggestion` field for actionable user guidance.
4
+ *
5
+ * Domain-specific repos extend this:
6
+ * - CLI: `GenfeedError extends BaseCliError`
7
+ * - Skills-Pro: `SkillsProError extends BaseCliError`
8
+ */
9
+ declare class BaseCliError extends Error {
10
+ suggestion?: string;
11
+ constructor(message: string, suggestion?: string);
12
+ }
13
+ /**
14
+ * Shared API error with HTTP status code.
15
+ * Used identically by CLI and skills-pro for HTTP client errors.
16
+ */
17
+ declare class ApiError extends BaseCliError {
18
+ statusCode?: number;
19
+ constructor(message: string, statusCode?: number, suggestion?: string);
20
+ }
21
+ /**
22
+ * Format an error for terminal display.
23
+ * Handles BaseCliError (with suggestion), generic Error, and unknown errors.
24
+ */
25
+ declare function formatError(error: unknown): string;
26
+ interface HandleErrorOptions {
27
+ /** When true, re-throws the error instead of exiting (for REPL mode). */
28
+ replMode?: boolean;
29
+ }
30
+ /**
31
+ * Print a formatted error and exit the process.
32
+ * Supports REPL mode where errors are re-thrown instead of calling process.exit.
33
+ */
34
+ declare function handleError(error: unknown, options?: HandleErrorOptions): never;
35
+
36
+ export { ApiError, BaseCliError, type HandleErrorOptions, formatError, handleError };
package/dist/index.js ADDED
@@ -0,0 +1,42 @@
1
+ import chalk from 'chalk';
2
+
3
+ // src/index.ts
4
+ var BaseCliError = class extends Error {
5
+ suggestion;
6
+ constructor(message, suggestion) {
7
+ super(message);
8
+ this.name = "BaseCliError";
9
+ this.suggestion = suggestion;
10
+ }
11
+ };
12
+ var ApiError = class extends BaseCliError {
13
+ statusCode;
14
+ constructor(message, statusCode, suggestion) {
15
+ super(message, suggestion);
16
+ this.name = "ApiError";
17
+ this.statusCode = statusCode;
18
+ }
19
+ };
20
+ function formatError(error) {
21
+ if (error instanceof BaseCliError) {
22
+ let output = chalk.red(`\u2716 ${error.message}`);
23
+ if (error.suggestion) {
24
+ output += `
25
+ ${chalk.dim(error.suggestion)}`;
26
+ }
27
+ return output;
28
+ }
29
+ if (error instanceof Error) {
30
+ return chalk.red(`\u2716 ${error.message}`);
31
+ }
32
+ return chalk.red("\u2716 An unknown error occurred");
33
+ }
34
+ function handleError(error, options) {
35
+ console.error(formatError(error));
36
+ if (options?.replMode) {
37
+ throw error;
38
+ }
39
+ process.exit(1);
40
+ }
41
+
42
+ export { ApiError, BaseCliError, formatError, handleError };
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@genfeedai/errors",
3
+ "version": "0.1.1",
4
+ "sideEffects": false,
5
+ "license": "MIT",
6
+ "description": "Shared error classes and formatting for Genfeed CLI tools",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/genfeedai/packages.git",
10
+ "directory": "errors"
11
+ },
12
+ "publishConfig": {
13
+ "access": "public",
14
+ "registry": "https://registry.npmjs.org/"
15
+ },
16
+ "main": "./dist/index.js",
17
+ "module": "./dist/index.mjs",
18
+ "types": "./dist/index.d.ts",
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "import": "./dist/index.mjs",
23
+ "require": "./dist/index.js"
24
+ }
25
+ },
26
+ "files": [
27
+ "dist"
28
+ ],
29
+ "scripts": {
30
+ "build": "tsup",
31
+ "dev": "tsup --watch",
32
+ "prepublishOnly": "bun run build"
33
+ },
34
+ "dependencies": {
35
+ "chalk": "5.6.2"
36
+ },
37
+ "devDependencies": {
38
+ "@types/node": "25.2.3",
39
+ "tsup": "8.4.0",
40
+ "typescript": "5.9.3"
41
+ },
42
+ "type": "module"
43
+ }