errlens 1.0.7 → 1.0.9

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.
Files changed (3) hide show
  1. package/README.md +26 -2
  2. package/bin/index.js +56 -34
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -54,8 +54,32 @@ npm install -g errlens
54
54
 
55
55
  ---
56
56
 
57
+ ## ⚡ Quick Start
58
+
59
+ ```bash
60
+ # Analyze an error message
61
+ errlens analyze "TypeError: Cannot read property 'name' of undefined"
62
+
63
+ # Run a script with error monitoring
64
+ errlens run your-script.js
65
+
66
+ # Get JSON output for CI/CD pipelines
67
+ errlens analyze "is not a function" --json
68
+ ```
69
+
70
+ ---
71
+
57
72
  ## 🛠 Usage
58
73
 
74
+ ### Available Commands
75
+
76
+ ```bash
77
+ errlens run <file> [--json] # Run a script and analyze any crashes
78
+ errlens analyze <error> [--json] # Analyze a specific error message
79
+ errlens --version # Show version information
80
+ errlens --help # Show help
81
+ ```
82
+
59
83
  ### 1️⃣ Automatic Monitoring (The "Pro" Way)
60
84
 
61
85
  Run your script through ErrLens. If it crashes, ErrLens intercepts the error and explains the fix before the process exits.
@@ -71,7 +95,7 @@ errlens run your-app.js
71
95
  Found a weird error in your logs? Just paste the message:
72
96
 
73
97
  ```bash
74
- errlens "TypeError: Cannot read properties of undefined"
98
+ errlens analyze "TypeError: Cannot read properties of undefined"
75
99
  ```
76
100
 
77
101
  ---
@@ -81,7 +105,7 @@ errlens "TypeError: Cannot read properties of undefined"
81
105
  Get machine-readable results for your own tooling or automated reports:
82
106
 
83
107
  ```bash
84
- errlens "is not a function" --json
108
+ errlens analyze "is not a function" --json
85
109
  ```
86
110
 
87
111
  Run a script and write the JSON report directly to a file in CI:
package/bin/index.js CHANGED
@@ -1,37 +1,41 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
 
3
3
  const { Command } = require("commander");
4
4
  const { spawn } = require("child_process");
5
-
6
5
  const chalk = require("chalk");
7
6
  const path = require("path");
8
7
  const { findError } = require("../lib/matcher");
9
8
  const { formatError } = require("../lib/formatter");
10
-
11
9
  const { version } = require("../package.json");
10
+
12
11
  const program = new Command();
13
12
 
14
13
  program
15
14
  .name("errlens")
16
15
  .description("Professional JS Error Analytics")
17
- .version(version);
16
+ .version(version)
17
+ .option("--json", "Output JSON instead of pretty UI"); // ✅ GLOBAL OPTION
18
18
 
19
19
  // ----------------- RUN COMMAND -----------------
20
20
  program
21
21
  .command("run <file>")
22
- .option('--json', 'Output JSON instead of pretty UI')
23
22
  .description("Run a Javascript file and analyze crashes")
24
- .action(async (file, options) => {
23
+ .action(async (file) => {
25
24
  const { default: ora } = await import("ora");
25
+
26
+ const isJson = Boolean(program.opts().json);
26
27
  const filePath = path.resolve(process.cwd(), file);
27
- const isJson = Boolean(options.json);
28
- const spinner = isJson ? null : ora(`Running ${chalk.yellow(file)}...`).start();
28
+ const spinner = isJson
29
+ ? null
30
+ : ora(`Running ${chalk.yellow(file)}...`).start();
29
31
 
30
- const child = spawn(process.execPath, [filePath], { stdio: ["inherit", "pipe", "pipe"] });
32
+ const child = spawn(process.execPath, [filePath], {
33
+ stdio: ["inherit", "pipe", "pipe"],
34
+ });
31
35
 
32
36
  let errorOutput = "";
33
37
 
34
- // Stream logs to terminal in real-time
38
+ // Stream stdout only in pretty mode
35
39
  child.stdout.on("data", (data) => {
36
40
  if (!isJson) {
37
41
  spinner.stop();
@@ -40,7 +44,7 @@ program
40
44
  }
41
45
  });
42
46
 
43
- // Capture stderr for analysis
47
+ // Capture stderr (DO NOT print in JSON mode)
44
48
  child.stderr.on("data", (data) => {
45
49
  errorOutput += data.toString();
46
50
 
@@ -50,34 +54,46 @@ program
50
54
  });
51
55
 
52
56
  child.on("close", (code, signal) => {
53
- if (!isJson) {
57
+ if (!isJson && spinner) {
54
58
  spinner.stop();
55
59
  }
56
60
 
57
61
  const { count, matches } = findError(errorOutput);
58
62
 
63
+ // Process killed by signal
59
64
  if (code === null) {
65
+ const result = { code: 1, count, matches };
66
+
60
67
  if (isJson) {
61
- const result = { code: 1, count, matches };
62
68
  console.log(JSON.stringify(result, null, 2));
63
69
  } else {
64
- console.log(chalk.red.bold(`\n⚠️ Process killed by signal: ${signal}`));
70
+ console.log(
71
+ chalk.red.bold(`\n⚠️ Process killed by signal: ${signal}`)
72
+ );
65
73
  }
74
+
66
75
  process.exit(1);
67
- return;
68
76
  }
69
77
 
78
+ // JSON MODE
70
79
  if (isJson) {
71
- const result = { code, count, matches };
72
- console.log(JSON.stringify(result, null, 2));
73
- } else if (code === 0) {
74
- console.log(chalk.green.bold("\n✨ Process finished successfully."));
80
+ console.log(JSON.stringify({ code, count, matches }, null, 2));
81
+ process.exit(code ?? 1);
82
+ }
83
+
84
+ // PRETTY MODE
85
+ if (code === 0) {
86
+ console.log(chalk.green.bold("\n✨ Process finished successfully."));
75
87
  } else {
76
88
  if (count > 0) {
77
- console.log(chalk.bold.cyan(`\n🚀 ErrLens Analysis (${count} Issue(s)):`));
78
- matches.forEach(m => { console.log(formatError(m)); }); // Pretty UI only here
89
+ console.log(
90
+ chalk.bold.cyan(`\n🚀 ErrLens Analysis (${count} Issue(s)):`)
91
+ );
92
+ matches.forEach((m) => console.log(formatError(m)));
79
93
  } else {
80
- console.log(chalk.red.bold("\n❌ Crash detected (No known fix in database):"));
94
+ console.log(
95
+ chalk.red.bold("\n❌ Crash detected (No known fix in database):")
96
+ );
81
97
  console.log(chalk.gray(errorOutput));
82
98
  }
83
99
  }
@@ -86,42 +102,48 @@ program
86
102
  });
87
103
 
88
104
  child.on("error", (err) => {
105
+ const result = { code: 1, count: 0, matches: [] };
106
+
89
107
  if (isJson) {
90
- const result = { code: 1, count: 0, matches: [] };
91
108
  console.log(JSON.stringify(result, null, 2));
92
109
  } else {
93
- spinner.fail(chalk.red(`System Error: ${err.message}`));
110
+ console.log(chalk.red(`System Error: ${err.message}`));
94
111
  }
112
+
95
113
  process.exit(1);
96
114
  });
97
115
  });
98
116
 
99
117
  // ----------------- ANALYZE COMMAND -----------------
100
118
  program
101
- .arguments("<errorString>") // default command if no "run"
119
+ .command("analyze <errorString>")
102
120
  .description("Analyze a specific error string")
103
- .option('--json', 'Output result in JSON format')
104
- .action((errorString, options) => {
121
+ .action((errorString) => {
122
+ const isJson = Boolean(program.opts().json);
105
123
  const { count, matches } = findError(errorString);
106
124
  const exitCode = count > 0 ? 1 : 0;
107
- const isJson = Boolean(options.json);
108
125
 
109
126
  if (isJson) {
110
- console.log(JSON.stringify({ code: exitCode, count, matches }, null, 2));
127
+ console.log(
128
+ JSON.stringify({ code: exitCode, count, matches }, null, 2)
129
+ );
111
130
  process.exit(exitCode);
112
- return;
113
131
  }
114
132
 
115
133
  if (count > 0) {
116
- console.log(chalk.bold.cyan(`\n🚀 ErrLens Analysis (${count} Issue(s)):`));
117
- matches.forEach(m => { console.log(formatError(m)); }); // Pretty UI
134
+ console.log(
135
+ chalk.bold.cyan(`\n🚀 ErrLens Analysis (${count} Issue(s)):`)
136
+ );
137
+ matches.forEach((m) => console.log(formatError(m)));
118
138
  } else {
119
- console.log(chalk.red.bold("\n❌ Crash detected (No known fix in database):"));
139
+ console.log(
140
+ chalk.red.bold("\n❌ Crash detected (No known fix in database):")
141
+ );
120
142
  console.log(chalk.gray(errorString));
121
143
  }
122
144
 
123
145
  process.exit(exitCode);
124
146
  });
125
147
 
126
- // ----------------- PARSE ARGUMENTS -----------------
148
+ // ----------------- PARSE -----------------
127
149
  program.parse(process.argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "errlens",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "Professional CLI tool that explains JavaScript and Node.js errors in plain English with actionable fixes directly in your terminal.",
5
5
  "main": "./bin/index.js",
6
6
  "bin": {
@@ -48,7 +48,7 @@
48
48
  },
49
49
  "dependencies": {
50
50
  "boxen": "^5.1.2",
51
- "chalk": "^4.1.2",
51
+ "chalk": "^5.6.2",
52
52
  "commander": "^14.0.3",
53
53
  "fuse.js": "^7.0.0",
54
54
  "ora": "^9.3.0"