error-less 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,204 @@
1
+ # error-less
2
+
3
+ > Beautiful, Rust-style error reporting for Node.js
4
+
5
+ [![npm version](https://img.shields.io/npm/v/error-less.svg)](https://www.npmjs.com/package/error-less)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ Transform noisy Node.js stack traces into beautiful, actionable error reports with source code context—just like Rust, Next.js, and other modern frameworks.
9
+
10
+ ## Features
11
+
12
+ - **Zero Configuration**: Just import and errors become beautiful
13
+ - **Source Code Context**: See the exact line that caused the error with surrounding code
14
+ - **Syntax Highlighting**: Code snippets are colorized for readability
15
+ - **Source Map Support**: Works with TypeScript and transpiled code
16
+ - **Smart Filtering**: Focuses on your code, not `node_modules`
17
+ - **Zero Runtime Cost**: Only activates when errors are thrown
18
+ - **Graceful Fallback**: Never crashes your app—falls back to standard traces if needed
19
+
20
+ ## Before & After
21
+
22
+ **Before (Standard Node.js):**
23
+ ```
24
+ TypeError: Cannot read properties of undefined (reading 'name')
25
+ at getUser (/app/src/services/user.ts:45:12)
26
+ at processRequest (/app/src/handlers/api.ts:23:8)
27
+ at /app/src/index.ts:67:5
28
+ ```
29
+
30
+ **After (error-less):**
31
+ ```
32
+ TypeError: Cannot read properties of undefined (reading 'name')
33
+ → ./src/services/user.ts:45:12
34
+
35
+ 43 │ function getUser(id: string) {
36
+ 44 │ const user = users.get(id);
37
+ > 45 │ return user.name;
38
+ │ ^^^
39
+ 46 │ }
40
+ 47 │
41
+
42
+ tip: Verify the value type matches what the operation expects
43
+ ```
44
+
45
+ ## Installation
46
+
47
+ ```bash
48
+ npm install error-less
49
+ ```
50
+
51
+ ## Quick Start
52
+
53
+ ### Zero-Config (Recommended)
54
+
55
+ Just import at the top of your entry file:
56
+
57
+ ```typescript
58
+ import 'error-less/register';
59
+
60
+ // Your code here...
61
+ throw new Error('Something went wrong!');
62
+ ```
63
+
64
+ ### Manual Installation
65
+
66
+ For more control:
67
+
68
+ ```typescript
69
+ import { install, configure } from 'error-less';
70
+
71
+ install({
72
+ showFullStack: true,
73
+ contextLinesBefore: 3,
74
+ contextLinesAfter: 3,
75
+ });
76
+ ```
77
+
78
+ ### Format Errors in try/catch
79
+
80
+ ```typescript
81
+ import { formatError } from 'error-less';
82
+
83
+ try {
84
+ riskyOperation();
85
+ } catch (error) {
86
+ console.error(formatError(error));
87
+ // Handle the error...
88
+ }
89
+ ```
90
+
91
+ ## Configuration Options
92
+
93
+ ```typescript
94
+ import { install } from 'error-less';
95
+
96
+ install({
97
+ // Lines of context before the error line (default: 2)
98
+ contextLinesBefore: 2,
99
+
100
+ // Lines of context after the error line (default: 2)
101
+ contextLinesAfter: 2,
102
+
103
+ // Enable source map resolution (default: true)
104
+ enableSourceMaps: true,
105
+
106
+ // Filter out node_modules frames (default: true)
107
+ filterNodeModules: true,
108
+
109
+ // Show full stack trace after code frame (default: false)
110
+ showFullStack: false,
111
+
112
+ // Force colors on/off (default: auto-detected)
113
+ colors: true,
114
+
115
+ // Custom frame filter
116
+ frameFilter: (frame) => !frame.filePath.includes('test'),
117
+ });
118
+ ```
119
+
120
+ ## API Reference
121
+
122
+ ### Core Functions
123
+
124
+ #### `install(config?: ErrorLessConfig): void`
125
+ Installs the custom stack trace handler.
126
+
127
+ #### `uninstall(): void`
128
+ Restores the original stack trace behavior.
129
+
130
+ #### `configure(config: Partial<ErrorLessConfig>): void`
131
+ Updates configuration without reinstalling.
132
+
133
+ #### `formatError(error: Error): string`
134
+ Returns a formatted error string. Useful for try/catch blocks.
135
+
136
+ #### `formatThrown(thrown: unknown): string`
137
+ Formats any thrown value (not just Error instances).
138
+
139
+ #### `isEnabled(): boolean`
140
+ Returns whether error-less is currently active.
141
+
142
+ ### Utility Functions
143
+
144
+ #### `getErrorFrames(error: Error): ParsedFrame[]`
145
+ Get parsed stack frames for advanced usage.
146
+
147
+ #### `clearFileCache(): void`
148
+ Clear the file content cache.
149
+
150
+ #### `clearSourceMapCache(): void`
151
+ Clear the source map consumer cache.
152
+
153
+ ## TypeScript Support
154
+
155
+ error-less is written in TypeScript and provides full type definitions.
156
+
157
+ ```typescript
158
+ import type { ErrorLessConfig, ParsedFrame } from 'error-less';
159
+ ```
160
+
161
+ ## Source Map Support
162
+
163
+ error-less automatically detects and uses source maps:
164
+
165
+ 1. **Inline source maps**: Embedded in the compiled file as base64
166
+ 2. **External source maps**: `.map` files alongside compiled files
167
+ 3. **Embedded source content**: Uses `sourcesContent` from maps when available
168
+
169
+ For TypeScript, ensure your `tsconfig.json` includes:
170
+
171
+ ```json
172
+ {
173
+ "compilerOptions": {
174
+ "sourceMap": true
175
+ }
176
+ }
177
+ ```
178
+
179
+ ## How It Works
180
+
181
+ error-less hooks into V8's `Error.prepareStackTrace` API. When an error's `.stack` property is accessed:
182
+
183
+ 1. The custom handler receives structured stack frame data
184
+ 2. Frames are parsed to extract file paths, line numbers, and columns
185
+ 3. Source maps are checked for original source locations
186
+ 4. Source files are read and code context is extracted
187
+ 5. A beautiful, syntax-highlighted output is generated
188
+
189
+ This approach has **zero performance impact** during normal execution—code only runs when an error is thrown and its stack is accessed.
190
+
191
+ ## Comparison
192
+
193
+ | Feature | error-less | pretty-error | youch |
194
+ |---------|-----------|--------------|-------|
195
+ | Zero config | ✅ | ❌ | ❌ |
196
+ | Source code display | ✅ | ❌ | ✅ |
197
+ | Source map support | ✅ | ❌ | ✅ |
198
+ | Syntax highlighting | ✅ | ❌ | ❌ |
199
+ | Smart filtering | ✅ | ✅ | ✅ |
200
+ | Pure terminal output | ✅ | ✅ | ❌ (HTML) |
201
+
202
+ ## License
203
+
204
+ MIT
@@ -0,0 +1,112 @@
1
+ import { P as ParsedFrame, C as CallSite, a as CodeContext, S as SourceMapResult, E as ErrorLessConfig, i as install } from './register-BG47xgjJ.mjs';
2
+ export { c as configure, d as defaultConfig, f as formatError, b as formatThrown, g as getConfig, e as getErrorFrames, h as isEnabled, u as uninstall } from './register-BG47xgjJ.mjs';
3
+
4
+ /**
5
+ * Stack Trace Parser
6
+ * Extracts structured information from V8 CallSite objects
7
+ */
8
+
9
+ /**
10
+ * Parse a single CallSite into a structured frame
11
+ */
12
+ declare function parseCallSite(callSite: CallSite): ParsedFrame | null;
13
+ /**
14
+ * Parse the entire structured stack trace
15
+ */
16
+ declare function parseStackTrace(structuredStack: CallSite[]): ParsedFrame[];
17
+ /**
18
+ * Find the first user code frame (the most relevant error location)
19
+ */
20
+ declare function findUserCodeFrame(frames: ParsedFrame[]): ParsedFrame | null;
21
+ /**
22
+ * Format a frame as a standard stack trace line
23
+ */
24
+ declare function formatFrameAsStackLine(frame: ParsedFrame): string;
25
+ /**
26
+ * Get relative path from current working directory
27
+ */
28
+ declare function getRelativePath(absolutePath: string): string;
29
+
30
+ /**
31
+ * Context Engine - Source File Reader
32
+ * Reads source files and extracts code context around error locations
33
+ */
34
+
35
+ /**
36
+ * Clear the file cache (useful for long-running processes)
37
+ */
38
+ declare function clearFileCache(): void;
39
+ /**
40
+ * Extract code context around a specific line
41
+ */
42
+ declare function getCodeContext(filePath: string, lineNumber: number, columnNumber: number, linesBefore?: number, linesAfter?: number): CodeContext | null;
43
+ /**
44
+ * Get code context for a parsed frame, with source map support
45
+ */
46
+ declare function getContextForFrame(frame: ParsedFrame, sourceMapResult: SourceMapResult | null, linesBefore?: number, linesAfter?: number): CodeContext | null;
47
+ /**
48
+ * Check if a file exists synchronously
49
+ */
50
+ declare function fileExists(filePath: string): boolean;
51
+
52
+ /**
53
+ * Source Map Support
54
+ * Resolves compiled code locations back to original source files
55
+ */
56
+
57
+ /**
58
+ * Resolve a frame location through source maps
59
+ */
60
+ declare function resolveSourceMap(frame: ParsedFrame): SourceMapResult | null;
61
+ /**
62
+ * Clear the source map cache
63
+ */
64
+ declare function clearSourceMapCache(): void;
65
+ /**
66
+ * Preload source-map module (no-op in built-in implementation)
67
+ */
68
+ declare function preloadSourceMapModule(): Promise<boolean>;
69
+
70
+ /**
71
+ * Renderer - Beautiful Terminal Error Output
72
+ * Creates Rust-style error displays with code frames and syntax highlighting
73
+ */
74
+
75
+ /**
76
+ * Main render function - creates the complete error display
77
+ */
78
+ declare function renderError(error: Error, topFrame: ParsedFrame | null, codeContext: CodeContext | null, allFrames: ParsedFrame[], sourceMapResult: SourceMapResult | null, config?: Required<ErrorLessConfig>): string;
79
+ /**
80
+ * Render a minimal error when we can't get context
81
+ */
82
+ declare function renderMinimalError(error: Error, frames: ParsedFrame[]): string;
83
+ /**
84
+ * Format an error for use in try/catch blocks
85
+ * Returns a string that can be logged
86
+ */
87
+ declare function formatErrorString(error: Error): string;
88
+
89
+ /**
90
+ * error-less
91
+ * Beautiful, Rust-style error reporting for Node.js
92
+ *
93
+ * @example
94
+ * // Auto-install with zero config
95
+ * import 'error-less/register';
96
+ *
97
+ * @example
98
+ * // Manual installation with options
99
+ * import { install } from 'error-less';
100
+ * install({ showFullStack: true });
101
+ *
102
+ * @example
103
+ * // Format errors in try/catch
104
+ * import { formatError } from 'error-less';
105
+ * try {
106
+ * riskyOperation();
107
+ * } catch (error) {
108
+ * console.error(formatError(error));
109
+ * }
110
+ */
111
+
112
+ export { CallSite, CodeContext, ErrorLessConfig, ParsedFrame, SourceMapResult, clearFileCache, clearSourceMapCache, install as default, fileExists, findUserCodeFrame, formatErrorString, formatFrameAsStackLine, getCodeContext, getContextForFrame, getRelativePath, install, parseCallSite, parseStackTrace, preloadSourceMapModule, renderError, renderMinimalError, resolveSourceMap };
@@ -0,0 +1,112 @@
1
+ import { P as ParsedFrame, C as CallSite, a as CodeContext, S as SourceMapResult, E as ErrorLessConfig, i as install } from './register-BG47xgjJ.js';
2
+ export { c as configure, d as defaultConfig, f as formatError, b as formatThrown, g as getConfig, e as getErrorFrames, h as isEnabled, u as uninstall } from './register-BG47xgjJ.js';
3
+
4
+ /**
5
+ * Stack Trace Parser
6
+ * Extracts structured information from V8 CallSite objects
7
+ */
8
+
9
+ /**
10
+ * Parse a single CallSite into a structured frame
11
+ */
12
+ declare function parseCallSite(callSite: CallSite): ParsedFrame | null;
13
+ /**
14
+ * Parse the entire structured stack trace
15
+ */
16
+ declare function parseStackTrace(structuredStack: CallSite[]): ParsedFrame[];
17
+ /**
18
+ * Find the first user code frame (the most relevant error location)
19
+ */
20
+ declare function findUserCodeFrame(frames: ParsedFrame[]): ParsedFrame | null;
21
+ /**
22
+ * Format a frame as a standard stack trace line
23
+ */
24
+ declare function formatFrameAsStackLine(frame: ParsedFrame): string;
25
+ /**
26
+ * Get relative path from current working directory
27
+ */
28
+ declare function getRelativePath(absolutePath: string): string;
29
+
30
+ /**
31
+ * Context Engine - Source File Reader
32
+ * Reads source files and extracts code context around error locations
33
+ */
34
+
35
+ /**
36
+ * Clear the file cache (useful for long-running processes)
37
+ */
38
+ declare function clearFileCache(): void;
39
+ /**
40
+ * Extract code context around a specific line
41
+ */
42
+ declare function getCodeContext(filePath: string, lineNumber: number, columnNumber: number, linesBefore?: number, linesAfter?: number): CodeContext | null;
43
+ /**
44
+ * Get code context for a parsed frame, with source map support
45
+ */
46
+ declare function getContextForFrame(frame: ParsedFrame, sourceMapResult: SourceMapResult | null, linesBefore?: number, linesAfter?: number): CodeContext | null;
47
+ /**
48
+ * Check if a file exists synchronously
49
+ */
50
+ declare function fileExists(filePath: string): boolean;
51
+
52
+ /**
53
+ * Source Map Support
54
+ * Resolves compiled code locations back to original source files
55
+ */
56
+
57
+ /**
58
+ * Resolve a frame location through source maps
59
+ */
60
+ declare function resolveSourceMap(frame: ParsedFrame): SourceMapResult | null;
61
+ /**
62
+ * Clear the source map cache
63
+ */
64
+ declare function clearSourceMapCache(): void;
65
+ /**
66
+ * Preload source-map module (no-op in built-in implementation)
67
+ */
68
+ declare function preloadSourceMapModule(): Promise<boolean>;
69
+
70
+ /**
71
+ * Renderer - Beautiful Terminal Error Output
72
+ * Creates Rust-style error displays with code frames and syntax highlighting
73
+ */
74
+
75
+ /**
76
+ * Main render function - creates the complete error display
77
+ */
78
+ declare function renderError(error: Error, topFrame: ParsedFrame | null, codeContext: CodeContext | null, allFrames: ParsedFrame[], sourceMapResult: SourceMapResult | null, config?: Required<ErrorLessConfig>): string;
79
+ /**
80
+ * Render a minimal error when we can't get context
81
+ */
82
+ declare function renderMinimalError(error: Error, frames: ParsedFrame[]): string;
83
+ /**
84
+ * Format an error for use in try/catch blocks
85
+ * Returns a string that can be logged
86
+ */
87
+ declare function formatErrorString(error: Error): string;
88
+
89
+ /**
90
+ * error-less
91
+ * Beautiful, Rust-style error reporting for Node.js
92
+ *
93
+ * @example
94
+ * // Auto-install with zero config
95
+ * import 'error-less/register';
96
+ *
97
+ * @example
98
+ * // Manual installation with options
99
+ * import { install } from 'error-less';
100
+ * install({ showFullStack: true });
101
+ *
102
+ * @example
103
+ * // Format errors in try/catch
104
+ * import { formatError } from 'error-less';
105
+ * try {
106
+ * riskyOperation();
107
+ * } catch (error) {
108
+ * console.error(formatError(error));
109
+ * }
110
+ */
111
+
112
+ export { CallSite, CodeContext, ErrorLessConfig, ParsedFrame, SourceMapResult, clearFileCache, clearSourceMapCache, install as default, fileExists, findUserCodeFrame, formatErrorString, formatFrameAsStackLine, getCodeContext, getContextForFrame, getRelativePath, install, parseCallSite, parseStackTrace, preloadSourceMapModule, renderError, renderMinimalError, resolveSourceMap };