errorxplain 1.0.0 → 1.1.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/workflows/npm-publish.yml +33 -0
- package/LICENSE +21 -0
- package/README.md +3 -0
- package/cover.png +0 -0
- package/lib/{rules/rules.json → default_rules.json} +2 -2
- package/lib/engine.js +31 -78
- package/lib/rules.js +27 -0
- package/package.json +1 -1
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
|
|
2
|
+
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
|
|
3
|
+
|
|
4
|
+
name: Node.js Package
|
|
5
|
+
|
|
6
|
+
on:
|
|
7
|
+
release:
|
|
8
|
+
types: [created]
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
build:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
- uses: actions/setup-node@v4
|
|
16
|
+
with:
|
|
17
|
+
node-version: 20
|
|
18
|
+
- run: npm ci
|
|
19
|
+
- run: npm test
|
|
20
|
+
|
|
21
|
+
publish-npm:
|
|
22
|
+
needs: build
|
|
23
|
+
runs-on: ubuntu-latest
|
|
24
|
+
steps:
|
|
25
|
+
- uses: actions/checkout@v4
|
|
26
|
+
- uses: actions/setup-node@v4
|
|
27
|
+
with:
|
|
28
|
+
node-version: 20
|
|
29
|
+
registry-url: https://registry.npmjs.org/
|
|
30
|
+
- run: npm ci
|
|
31
|
+
- run: npm publish
|
|
32
|
+
env:
|
|
33
|
+
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Surya Shashank Neupane
|
|
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
CHANGED
package/cover.png
ADDED
|
Binary file
|
package/lib/engine.js
CHANGED
|
@@ -1,88 +1,41 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import path from "path";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
import { loadRules, getRules } from "./rules.js";
|
|
3
5
|
|
|
4
|
-
|
|
6
|
+
// __dirname fix
|
|
7
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
+
const __dirname = path.dirname(__filename);
|
|
5
9
|
|
|
6
|
-
|
|
7
|
-
|
|
10
|
+
const LOGS_DIR = path.join(process.cwd(), "logs");
|
|
11
|
+
if (!fs.existsSync(LOGS_DIR)) fs.mkdirSync(LOGS_DIR);
|
|
8
12
|
|
|
9
|
-
//
|
|
10
|
-
const filePositions = {};
|
|
11
|
-
|
|
12
|
-
// Load rules from JSON and convert patterns to RegExp
|
|
13
|
-
function loadRules() {
|
|
14
|
-
try {
|
|
15
|
-
const rawRules = JSON.parse(fs.readFileSync(rulesFile, "utf8"));
|
|
16
|
-
rules = rawRules.map(r => ({ ...r, pattern: new RegExp(r.pattern) }));
|
|
17
|
-
console.log(`Loaded ${rules.length} error rules`);
|
|
18
|
-
} catch (err) {
|
|
19
|
-
console.error("Failed to load rules.json:", err.message);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// Initial load
|
|
13
|
+
// Load rules once at startup
|
|
24
14
|
loadRules();
|
|
25
15
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (match) return match;
|
|
36
|
-
return { meaning: "Unknown error", fix: "Search documentation or logs" };
|
|
16
|
+
function applyRules(logContent) {
|
|
17
|
+
const rules = getRules();
|
|
18
|
+
rules.forEach((rule) => {
|
|
19
|
+
if (logContent.includes(rule.pattern)) {
|
|
20
|
+
console.log(` Detected: ${rule.pattern}`);
|
|
21
|
+
console.log(` Meaning: ${rule.meaning}`);
|
|
22
|
+
console.log(` Fix: ${rule.fix}\n`);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
37
25
|
}
|
|
38
26
|
|
|
39
|
-
// Watch logs
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const filePath = path.join(logDir, filename);
|
|
53
|
-
|
|
54
|
-
// Initialize last position
|
|
55
|
-
if (!filePositions[filePath]) filePositions[filePath] = 0;
|
|
56
|
-
|
|
57
|
-
fs.stat(filePath, (err, stats) => {
|
|
58
|
-
if (err) return console.error("Stat error:", err.message);
|
|
59
|
-
|
|
60
|
-
const prevSize = filePositions[filePath];
|
|
61
|
-
const newSize = stats.size;
|
|
62
|
-
|
|
63
|
-
// Only read new content
|
|
64
|
-
if (newSize > prevSize) {
|
|
65
|
-
const stream = fs.createReadStream(filePath, {
|
|
66
|
-
start: prevSize,
|
|
67
|
-
end: newSize
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
let data = "";
|
|
71
|
-
stream.on("data", chunk => (data += chunk));
|
|
72
|
-
stream.on("end", () => {
|
|
73
|
-
filePositions[filePath] = newSize;
|
|
74
|
-
|
|
75
|
-
const lines = data.split("\n").filter(line => line.trim() !== "");
|
|
76
|
-
lines.forEach(line => {
|
|
77
|
-
const explanation = explainError(line);
|
|
78
|
-
if (explanation.meaning !== "Unknown error") {
|
|
79
|
-
console.log("\nDetected Error:\n", explanation, "\n");
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
});
|
|
27
|
+
// Watch logs folder
|
|
28
|
+
fs.watch(LOGS_DIR, (eventType, filename) => {
|
|
29
|
+
if (filename && eventType === "change") {
|
|
30
|
+
const filePath = path.join(LOGS_DIR, filename);
|
|
31
|
+
try {
|
|
32
|
+
const logContent = fs.readFileSync(filePath, "utf-8");
|
|
33
|
+
console.log(`\nDetected change in ${filename}`);
|
|
34
|
+
applyRules(logContent);
|
|
35
|
+
} catch (err) {
|
|
36
|
+
console.error(`Failed to read ${filename}:`, err.message);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
});
|
|
83
40
|
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
}
|
|
41
|
+
console.log(`Watching logs at ${LOGS_DIR}...`);
|
package/lib/rules.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
|
|
5
|
+
// __dirname fix for ES Modules
|
|
6
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
7
|
+
const __dirname = path.dirname(__filename);
|
|
8
|
+
|
|
9
|
+
// Point to the new bundled file
|
|
10
|
+
const defaultRulesPath = path.join(__dirname, "default_rules.json");
|
|
11
|
+
|
|
12
|
+
let rulesCache = [];
|
|
13
|
+
|
|
14
|
+
export function loadRules() {
|
|
15
|
+
try {
|
|
16
|
+
const data = fs.readFileSync(defaultRulesPath, "utf-8");
|
|
17
|
+
rulesCache = JSON.parse(data).rules;
|
|
18
|
+
console.log(`Loaded ${rulesCache.length} bundled rules`);
|
|
19
|
+
} catch (err) {
|
|
20
|
+
console.error("Failed to load bundled rules:", err.message);
|
|
21
|
+
rulesCache = [];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function getRules() {
|
|
26
|
+
return rulesCache;
|
|
27
|
+
}
|