errlens 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/.github/dependabot.yml +21 -0
- package/.github/workflow/nodejs.yml +23 -0
- package/LICENSE +21 -0
- package/README.md +115 -0
- package/assets/errlens.png +0 -0
- package/assets/terminal.png +0 -0
- package/bin/index.js +48 -0
- package/lib/auto.js +16 -0
- package/lib/database.json +38 -0
- package/lib/formatter.js +35 -0
- package/lib/matcher.js +25 -0
- package/package.json +29 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
version: 2
|
|
2
|
+
updates:
|
|
3
|
+
# Maintain dependencies for npm
|
|
4
|
+
- package-ecosystem: "npm"
|
|
5
|
+
directory: "/" # Location of package.json
|
|
6
|
+
schedule:
|
|
7
|
+
interval: "weekly"
|
|
8
|
+
day: "monday"
|
|
9
|
+
open-pull-requests-limit: 5
|
|
10
|
+
# Label PRs so they are easy to filter
|
|
11
|
+
labels:
|
|
12
|
+
- "dependencies"
|
|
13
|
+
- "javascript"
|
|
14
|
+
|
|
15
|
+
# Maintain GitHub Actions
|
|
16
|
+
- package-ecosystem: "github-actions"
|
|
17
|
+
directory: "/"
|
|
18
|
+
schedule:
|
|
19
|
+
interval: "weekly"
|
|
20
|
+
labels:
|
|
21
|
+
- "ci/cd"
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# .github/workflows/nodejs.yml
|
|
2
|
+
name: Node.js CI
|
|
3
|
+
|
|
4
|
+
on:
|
|
5
|
+
push:
|
|
6
|
+
branches: [ main ]
|
|
7
|
+
pull_request:
|
|
8
|
+
branches: [ main ]
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
build:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v3
|
|
16
|
+
- name: Use Node.js 18
|
|
17
|
+
uses: actions/setup-node@v3
|
|
18
|
+
with:
|
|
19
|
+
node-version: 18
|
|
20
|
+
|
|
21
|
+
- run: npm install
|
|
22
|
+
- run: npm run lint || echo "Skipping lint if not set"
|
|
23
|
+
- run: npm test || echo "Skipping test if not set"
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 BeyteFlow
|
|
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,115 @@
|
|
|
1
|
+
# ErrLens π
|
|
2
|
+
> **Translate cryptic JavaScript errors into human-readable solutions instantly.**
|
|
3
|
+
|
|
4
|
+
<p align="left">
|
|
5
|
+
<img src="https://img.shields.io/npm/v/errlens?style=flat-square&color=007acc" alt="npm version">
|
|
6
|
+
<img src="https://img.shields.io/github/license/BeyteFlow/errlens?style=flat-square&color=42b883" alt="license">
|
|
7
|
+
<img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square" alt="PRs Welcome">
|
|
8
|
+
</p>
|
|
9
|
+
|
|
10
|
+
**ErrLens** is a professional-grade CLI utility designed to eliminate developer frustration. It intercepts Node.js crashes, analyzes stack traces, and delivers plain-English explanations with actionable fixesβdirectly in your terminal.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## π Key Features
|
|
15
|
+
|
|
16
|
+
- π **Instant Diagnostics** β No more context-switching to Google or StackOverflow.
|
|
17
|
+
- π **Live Monitoring** β Catch errors in real-time using the `errlens run` command.
|
|
18
|
+
- π§ **Fuzzy Logic Engine** β Matches messy stack traces and typos using `Fuse.js`.
|
|
19
|
+
- π¨ **Beautiful UI** β High-visibility terminal output powered by `boxen` and `chalk`.
|
|
20
|
+
- π€ **CI/CD Ready** β Export raw data via `--json` for automated error reporting.
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## π¦ Installation
|
|
25
|
+
|
|
26
|
+
Install globally via npm to use the `errlens` command anywhere in your terminal:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install -g errlens
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## π Usage
|
|
35
|
+
|
|
36
|
+
### 1οΈβ£ Automatic Monitoring (The "Pro" Way)
|
|
37
|
+
|
|
38
|
+
Run your script through ErrLens. If it crashes, ErrLens intercepts the error and explains the fix before the process exits.
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
errlens run your-app.js
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
### 2οΈβ£ Manual Analysis
|
|
47
|
+
|
|
48
|
+
Found a weird error in your logs? Just paste the message:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
errlens "TypeError: Cannot read properties of undefined"
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
### 3οΈβ£ Pipeline Integration
|
|
57
|
+
|
|
58
|
+
Get machine-readable results for your own tooling or automated reports:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
errlens "is not a function" --json
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## π§ System Architecture
|
|
67
|
+
|
|
68
|
+
ErrLens operates on a three-stage intelligent pipeline to turn confusion into clarity:
|
|
69
|
+
|
|
70
|
+
| Phase | Component | Description |
|
|
71
|
+
|---------------|----------------|-------------|
|
|
72
|
+
| Interception | `auto.js` | Hooks into the `uncaughtException` event via a preload script. |
|
|
73
|
+
| Matching | `matcher.js` | Uses fuzzy search against `database.json` to find the root cause. |
|
|
74
|
+
| Formatting | `formatter.js` | Wraps the diagnosis in a clean, color-coded terminal interface. |
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## π Project Structure
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
errlens/
|
|
82
|
+
βββ bin/index.js # CLI Entry point & Command routing
|
|
83
|
+
βββ lib/
|
|
84
|
+
β βββ matcher.js # Fuzzy search & Logic engine
|
|
85
|
+
β βββ formatter.js # UI & Terminal styling
|
|
86
|
+
β βββ auto.js # Automation & Error interception
|
|
87
|
+
β βββ database.json # The "Knowledge Base" (Dictionary)
|
|
88
|
+
βββ package.json # Dependencies & Metadata
|
|
89
|
+
βββ README.md # Documentation
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## π€ Contributing
|
|
95
|
+
|
|
96
|
+
We are building the world's most comprehensive dictionary of JavaScript errors, and we need your help!
|
|
97
|
+
|
|
98
|
+
1. Fork the repository.
|
|
99
|
+
2. Add a new error entry to `lib/database.json`.
|
|
100
|
+
3. Submit a Pull Request.
|
|
101
|
+
|
|
102
|
+
π‘ **Tip:** Every error you add helps another developer save valuable time. Join the mission!
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## π License
|
|
107
|
+
|
|
108
|
+
Distributed under the MIT License. See `LICENSE` for more information.
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
<p align="center">
|
|
113
|
+
Built with β€οΈ by <b>BeyteFlow</b><br>
|
|
114
|
+
<i>Making the terminal a friendlier place, one error at a time.</i>
|
|
115
|
+
</p>
|
|
Binary file
|
|
Binary file
|
package/bin/index.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { Command } = require("commander");
|
|
4
|
+
const ora = require("ora");
|
|
5
|
+
const chalk = require("chalk");
|
|
6
|
+
const { findError } = require("../lib/matcher");
|
|
7
|
+
const { formatError } = require("../lib/formatter");
|
|
8
|
+
|
|
9
|
+
const program = new Command();
|
|
10
|
+
|
|
11
|
+
program
|
|
12
|
+
.name("errlens")
|
|
13
|
+
.description("Professional JS error analysis for the terminal")
|
|
14
|
+
.version("1.1.0")
|
|
15
|
+
.argument("[error]", "The error message to analyze")
|
|
16
|
+
.option("-j, --json", "Output results in raw JSON format") // For automation
|
|
17
|
+
.action((errorInput, options) => {
|
|
18
|
+
// If no argument is provided, show help and exit
|
|
19
|
+
if (!errorInput) {
|
|
20
|
+
program.help();
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// JSON Mode (No spinner, no colors, just data)
|
|
25
|
+
if (options.json) {
|
|
26
|
+
const result = findError(errorInput);
|
|
27
|
+
console.log(JSON.stringify(result || { error: "No match found" }, null, 2));
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Standard Mode
|
|
32
|
+
const spinner = ora({ text: "Analyzing error trace...", color: "cyan" }).start();
|
|
33
|
+
|
|
34
|
+
setTimeout(() => {
|
|
35
|
+
const result = findError(errorInput);
|
|
36
|
+
|
|
37
|
+
if (!result) {
|
|
38
|
+
spinner.fail(chalk.red(" Analysis Failed: Error not found in database."));
|
|
39
|
+
console.log(chalk.dim("\nTry searching a shorter snippet of the error message."));
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
spinner.succeed(chalk.bold("Analysis complete!"));
|
|
44
|
+
console.log(formatError(result));
|
|
45
|
+
}, 500);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
program.parse(process.argv);
|
package/lib/auto.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// lib/auto.js
|
|
2
|
+
const { findError } = require("./matcher");
|
|
3
|
+
const { formatError } = require("./formatter");
|
|
4
|
+
|
|
5
|
+
// This listens for any crash that wasn't caught by a try/catch
|
|
6
|
+
process.on("uncaughtException", (err) => {
|
|
7
|
+
const result = findError(err.message);
|
|
8
|
+
|
|
9
|
+
if (result) {
|
|
10
|
+
console.log("\n--- ErrLens Auto-Detection ---");
|
|
11
|
+
console.log(formatError(result));
|
|
12
|
+
} else {
|
|
13
|
+
console.error(err);
|
|
14
|
+
}
|
|
15
|
+
process.exit(1);
|
|
16
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"name": "TypeError: Cannot read properties of undefined",
|
|
4
|
+
"match": "Cannot read properties of undefined",
|
|
5
|
+
"explanation": "You are trying to access a property (like .map, .length, or .id) on a variable that currently holds no value.",
|
|
6
|
+
"why": "The variable wasn't initialized, an API call hasn't finished yet, or a function returned nothing.",
|
|
7
|
+
"fixes": [
|
|
8
|
+
"Use optional chaining: user?.profile",
|
|
9
|
+
"Set a default value: const list = data || []",
|
|
10
|
+
"Check if the variable exists: if (data) { ... }"
|
|
11
|
+
],
|
|
12
|
+
"example": "const name = user?.info?.name || 'Guest';"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"name": "ReferenceError: x is not defined",
|
|
16
|
+
"match": "is not defined",
|
|
17
|
+
"explanation": "You're trying to use a variable that hasn't been declared in the current scope.",
|
|
18
|
+
"why": "Possible typo in the variable name, or the variable is scoped inside another function/block.",
|
|
19
|
+
"fixes": [
|
|
20
|
+
"Check for typos in the variable name",
|
|
21
|
+
"Ensure the variable is declared with const, let, or var",
|
|
22
|
+
"Check if the variable is defined outside the current function"
|
|
23
|
+
],
|
|
24
|
+
"example": "const myVar = 10;\nconsole.log(myVar); // Ensure name matches exactly"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"name": "TypeError: x is not a function",
|
|
28
|
+
"match": "is not a function",
|
|
29
|
+
"explanation": "You tried to call a variable as if it were a function, but it's a different data type (like a String or Object).",
|
|
30
|
+
"why": "Often happens when an import fails or when a callback isn't passed correctly.",
|
|
31
|
+
"fixes": [
|
|
32
|
+
"Verify the variable is actually a function with typeof",
|
|
33
|
+
"Check your imports/requires",
|
|
34
|
+
"Ensure you aren't overwriting the function name with a value"
|
|
35
|
+
],
|
|
36
|
+
"example": "if (typeof callback === 'function') {\n callback();\n}"
|
|
37
|
+
}
|
|
38
|
+
]
|
package/lib/formatter.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const chalk = require("chalk");
|
|
2
|
+
const boxen = require("boxen");
|
|
3
|
+
|
|
4
|
+
function formatError(error) {
|
|
5
|
+
const fixList = error.fixes
|
|
6
|
+
.map(fix => chalk.green(` β ${fix}`))
|
|
7
|
+
.join("\n");
|
|
8
|
+
|
|
9
|
+
const content = `
|
|
10
|
+
${chalk.cyan.bold("ID:")} ${error.name}
|
|
11
|
+
|
|
12
|
+
${chalk.yellow.bold("π WHAT HAPPENED:")}
|
|
13
|
+
${error.explanation}
|
|
14
|
+
|
|
15
|
+
${chalk.magenta.bold("π₯ WHY:")}
|
|
16
|
+
${error.why}
|
|
17
|
+
|
|
18
|
+
${chalk.green.bold("β
COMMON FIXES:")}
|
|
19
|
+
${fixList}
|
|
20
|
+
|
|
21
|
+
${chalk.blue.bold("π EXAMPLE:")}
|
|
22
|
+
${chalk.gray(error.example)}
|
|
23
|
+
`;
|
|
24
|
+
|
|
25
|
+
return boxen(content, {
|
|
26
|
+
padding: 1,
|
|
27
|
+
margin: 1,
|
|
28
|
+
borderStyle: "round",
|
|
29
|
+
borderColor: "cyan",
|
|
30
|
+
title: "ErrLens Analysis",
|
|
31
|
+
titleAlignment: "center"
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
module.exports = { formatError };
|
package/lib/matcher.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const Fuse = require("fuse.js");
|
|
2
|
+
const database = require("./database.json");
|
|
3
|
+
|
|
4
|
+
function findError(input) {
|
|
5
|
+
if (!input) return null;
|
|
6
|
+
|
|
7
|
+
// Clean the input:
|
|
8
|
+
// 1. Take only the first line (the error message).
|
|
9
|
+
// 2. Remove common noise like 'Uncaught' or file paths.
|
|
10
|
+
const coreError = input.split('\n')[0]
|
|
11
|
+
.replace(/^Uncaught\s+/, '')
|
|
12
|
+
.split(' at ')[0]
|
|
13
|
+
.trim();
|
|
14
|
+
|
|
15
|
+
const fuse = new Fuse(database, {
|
|
16
|
+
keys: ["match", "name"],
|
|
17
|
+
threshold: 0.4, // Balance between strict and loose
|
|
18
|
+
distance: 100
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const result = fuse.search(coreError);
|
|
22
|
+
return result.length > 0 ? result[0].item : null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
module.exports = { findError };
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "errlens",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A CLI tool that explains JavaScript/Node.js errors in plain English.",
|
|
5
|
+
"main": "./bin/index.js",
|
|
6
|
+
"author": "BeyteFlow (https://github.com/BeyteFlow)",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"bin": {
|
|
9
|
+
"errlens": "./bin/index.js"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"test": "node --test test/**/*.test.js"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/BeyteFlow/errlens.git"
|
|
17
|
+
},
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/BeyteFlow/errlens/issues"
|
|
20
|
+
},
|
|
21
|
+
"homepage": "https://github.com/BeyteFlow/errlens#readme",
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"boxen": "^5.1.2",
|
|
24
|
+
"chalk": "^4.1.2",
|
|
25
|
+
"commander": "^11.1.0",
|
|
26
|
+
"fuse.js": "^7.0.0",
|
|
27
|
+
"ora": "^5.4.1"
|
|
28
|
+
}
|
|
29
|
+
}
|