Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ program
program
.command("run <file>")
.description("Run a Javascript file and analyze crashes")
.action(async (file) => {
.option("--lang <code>", "output language (e.g. hi, es, fr)", "en")

.action(async (file,options) => {
const { default: ora } = await import("ora");
const { default: chalk } = await import("chalk");

const isJson = Boolean(program.opts().json);
const filePath = path.resolve(process.cwd(), file);
const spinner = isJson
Expand Down Expand Up @@ -58,7 +60,7 @@ program
spinner.stop();
}

const { count, matches } = findError(errorOutput);
const { count, matches } = findError(errorOutput,options.lang);

// Process killed by signal
if (code === null) {
Expand Down Expand Up @@ -119,10 +121,14 @@ program
program
.command("analyze <errorString>")
.description("Analyze a specific error string")
.action(async (errorString) => {
.option("--lang <code>", "output language (e.g. hi, es, fr)", "en")
.argument("<error>", "error to explain")


.action(async (errorString,options) => {
const { default: chalk } = await import("chalk");
const isJson = Boolean(program.opts().json);
const { count, matches } = findError(errorString);
const { count, matches } = findError(errorString,options.lang);
const exitCode = count > 0 ? 1 : 0;

if (isJson) {
Expand All @@ -143,9 +149,11 @@ program
);
console.log(chalk.gray(errorString));
}


process.exit(exitCode);
});


// ----------------- PARSE -----------------
program.parse(process.argv);
13 changes: 13 additions & 0 deletions i18n.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "https://lingo.dev/schema/i18n.json",
"version": "1.10",
"locale": {
"source": "en",
"targets": ["hi", "es", "fr", "de", "zh", "ja", "pt"]
},
"buckets": {
"json": {
"include": ["locales/[locale].json"]
}
}
}
200 changes: 200 additions & 0 deletions i18n.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
version: 1
checksums:
cd45f366fd2727f232266877d34abf6c:
Cannot%20read%20properties%20of%20undefined__explanation: 1faad15c888b2a1290951e18cdb08273
Cannot%20read%20properties%20of%20undefined__why: 3179b160bec861271f4602ebe55c69fc
Cannot%20read%20properties%20of%20undefined__fix_0: d932abe8f516daa322109d173a0a7392
Cannot%20read%20properties%20of%20undefined__fix_1: a00a5d6e5e2580841669adfb73347a51
is%20not%20defined__explanation: dce4ec23c37a84423385142723d57e69
is%20not%20defined__why: d9208afa3d7b9ac25f73ea3baa18031d
is%20not%20defined__fix_0: 2d295bfe46fd45f74dcbf672bd6942dc
is%20not%20defined__fix_1: 19f5707dd78dbdfcf7ded717b3b8492b
is%20not%20a%20function__explanation: 918b8c29a15c20b52933bf461837d804
is%20not%20a%20function__why: c6dbd2a1a5eca3d350f367d46897634d
is%20not%20a%20function__fix_0: 7e5c2caf094f77d67b7da2ecf48617a8
is%20not%20a%20function__fix_1: 8ca8156b6dce6bc3de4b917229507664
Cannot%20find%20module__explanation: df9406f032055379c122b11bbc8442cc
Cannot%20find%20module__why: 9c217ca8d54e7f11908515b2248477a9
Cannot%20find%20module__fix_0: 6e59ba46293292bd210b68c33071994f
Cannot%20find%20module__fix_1: 1b75b725b28f5ce62639646665abe136
EADDRINUSE__explanation: 4995bf9b29964b8b25c075f7d57c8c8f
EADDRINUSE__why: 8a4e66e0ad693b72654065ff11050c78
EADDRINUSE__fix_0: 3fa6768935a227288578444de0e4bd5c
EADDRINUSE__fix_1: f739e9e9d476c7b64f32caaf3eb45fe7
Maximum%20call%20stack%20size%20exceeded__explanation: d7e9786db5ed21d73cb4050b3b898834
Maximum%20call%20stack%20size%20exceeded__why: 8d946b4ef685c6449c6d84beb7017d1b
Maximum%20call%20stack%20size%20exceeded__fix_0: ad83507bcca1effe6dc64bb3cbaabd47
Maximum%20call%20stack%20size%20exceeded__fix_1: 948409dfcc1435c2f5efecc96f00d594
Maximum%20call%20stack%20size%20exceeded__fix_2: 3095f0d91f9a2daf9debfa890d14f647
ECONNREFUSED__explanation: 09cfe66dfe9a9699b568c8a81ea78667
ECONNREFUSED__why: 33e4dc458a905ccbc06674166145b507
ECONNREFUSED__fix_0: f0103434e2f0ef263c630e8151e47ad6
ECONNREFUSED__fix_1: 540ac446681c52c37928c7c603a113d7
Assignment%20to%20constant%20variable__explanation: 2f92f627fc27f0dfd26ae883f0603e88
Assignment%20to%20constant%20variable__why: d34c7aafddcc8437800fa988e4f4e3b1
Assignment%20to%20constant%20variable__fix_0: 7a2d22d9c19f5de0231f4e99852e0de6
ENOENT__explanation: 5dd4798e91f081b27a285ad456bbe270
ENOENT__why: b7460a442b46fb2f1247206a1e7bd4ac
ENOENT__fix_0: 3cabfd4520d70d49b2872196bd34c9a8
ENOENT__fix_1: 4150f9d558b7ecd2b690c530fa485852
await%20is%20only%20valid%20in%20async%20functions__explanation: 84644d836d3b797652d2dbcd740f863f
await%20is%20only%20valid%20in%20async%20functions__why: 6b3e619695d4346fdf4a86f20d747522
await%20is%20only%20valid%20in%20async%20functions__fix_0: 188259beff59af55b9bf30fc52d56b91
ERR_HTTP_HEADERS_SENT__explanation: 643952cd42e9568de7db01258a1054db
ERR_HTTP_HEADERS_SENT__why: c60cc02c5ec72480b94206c0d743ecca
ERR_HTTP_HEADERS_SENT__fix_0: c4f03ca555bedb02445a99d00c43d7cb
buffering%20timed%20out__explanation: 3619c59abd5eff53f070ef5eb98ab0f2
buffering%20timed%20out__why: 2e31b51184aeb28c6d0d246accd5f6dd
buffering%20timed%20out__fix_0: a35ed84c50d70b1f8dcb1f8c63697247
buffering%20timed%20out__fix_1: 395dbe26dba7ba3ccd023c3c67c4bc3c
jwt%20malformed__explanation: 62caf4e3abe069f9fe55d3e96e216ff3
jwt%20malformed__why: 93e9616fbb61db7bde6144993dd6df45
jwt%20malformed__fix_0: b4721afa33ebba6471811bdc73742d4b
jwt%20malformed__fix_1: 64d3e1e626f7575e36e40854911094d7
secretOrPrivateKey%20must%20have%20a%20value__explanation: a855a5dd85b11b07bd5722d4a3734dac
secretOrPrivateKey%20must%20have%20a%20value__why: d002ae95fc21841550a9585b32d2e04d
secretOrPrivateKey%20must%20have%20a%20value__fix_0: 6272ebcc4a5d59438b50915e89dada86
secretOrPrivateKey%20must%20have%20a%20value__fix_1: b85bc80c89a251cfb859c2d3567f592e
E11000__explanation: a3d6e7324f1267c2383493d2e7c1b936
E11000__why: 37d84f4f32d319a84a26164befa1f78c
E11000__fix_0: 2744aaaeea21ffd2adc261b857643e87
E11000__fix_1: a00adf9185b256903bd698fb60188e32
Unexpected%20token%20%3C%20in%20JSON__explanation: 35336685e8d2c76f0b974242330d0975
Unexpected%20token%20%3C%20in%20JSON__why: 9f8109ebe11f962d57111a3093aae6e1
Unexpected%20token%20%3C%20in%20JSON__fix_0: 3b9f95f3402a90c30acb9736b0256c21
Unexpected%20token%20%3C%20in%20JSON__fix_1: c82a2a9ddef7ce33e3219fe32981e4a3
CORS__explanation: 70b04e3e9ed6defefcf2f37a8243ee3a
CORS__why: 27bc6fa1656b9568ac942af065d125df
CORS__fix_0: de5acdf0270111e93173e98f0c572023
CORS__fix_1: 7e0d316d062534aff39bcb246bd39fc4
"'map'%20of%20undefined__explanation": 8623a6fb138a0da5404ad67141f58fc1
"'map'%20of%20undefined__why": b9c6b5e5cf6251c4d18af9020a62be06
"'map'%20of%20undefined__fix_0": b351521f10b0078582478655bb439229
"'map'%20of%20undefined__fix_1": d2988c5969a78ac503c95e1031a437ca
module%20not%20found%20'dotenv'__explanation: b5c0e169b532c55bcdacc55555cedaa8
module%20not%20found%20'dotenv'__why: b7f34bd59ad6954385fa9fa777371c60
module%20not%20found%20'dotenv'__fix_0: 81544c6dba548915dec5a52ee629bce3
validation%20failed__explanation: 9d9af2de697f93326e47c48ef6582afe
validation%20failed__why: 43b5aa9edd5d2ac09074aac05dd1bbfe
validation%20failed__fix_0: 0448d5d0a5a7ff829295070cee22e9a9
validation%20failed__fix_1: 6165448b86d2e59b8220d54f147580e2
not%20authorized__explanation: 54f27844a9f0542f38fbed4541624a5a
not%20authorized__why: 67438e33beea817e67a16603dae9167e
not%20authorized__fix_0: cad7a414147406f1d540fe86e36c7d64
not%20authorized__fix_1: 4d85b636feb04be3fcc9555cea3bdb88
status%20code%20404__explanation: bbca7ace5b0d257a209686ffb3ccfe1e
status%20code%20404__why: 0e117e5d305279246d9102a284030a9a
status%20code%20404__fix_0: 8aa5265e1eecebe9585b480deb000478
status%20code%20404__fix_1: 9bc8e39d5fe836a76cffbedd96c9e313
status%20code%20500__explanation: 4bfedfc76ec3c8b6df5afc2227dc3be2
status%20code%20500__why: 04d5760a4000b7abc051f950ff3b3304
status%20code%20500__fix_0: e5b5c7452f20066c4f88f4fd640478b0
status%20code%20500__fix_1: af06db7991552f8c69bbff51d9ade46a
is%20not%20iterable__explanation: 3b3554d0eac3e54b65b51ff4de623147
is%20not%20iterable__why: d39026cb5bc0447e54a2a47063e9663a
is%20not%20iterable__fix_0: e455c6d763a0ae1a542c7147db65c4b0
is%20not%20iterable__fix_1: bf65ea0c6fb4621a86bc527e0747b960
require%20is%20not%20defined__explanation: 61b6c906a5e79fec3d07396f34e535ae
require%20is%20not%20defined__why: 3f9107676033f1badc6333c02cacd6c2
require%20is%20not%20defined__fix_0: e854fadced8da6eeeae440d812cb2679
require%20is%20not%20defined__fix_1: d753e9ed9a895284f2039bb6ff807b6f
EACCES__explanation: dc5e4f5e04000d8837521bebc39de36d
EACCES__why: 5f2c6e7f7208d5eecd95b7f6231103cb
EACCES__fix_0: ef078af144e4986187275484df386266
EACCES__fix_1: 7f454605e663b32829d824fa3b108369
has%20already%20been%20declared__explanation: 6bf7939de2636631859b552bd310b444
has%20already%20been%20declared__why: 1a04b61b7eb912688c26d209106a6f84
has%20already%20been%20declared__fix_0: ad701a6992f6a413b925a0095d9d96c6
has%20already%20been%20declared__fix_1: 9a8203cbe924bbd09661888930839719
PayloadTooLargeError__explanation: 41aabf96fbf310855061542734dd3914
PayloadTooLargeError__why: 81e39285e49ba8e7ff06b1f5e700faa0
PayloadTooLargeError__fix_0: 036e8726757ecf562416d8fbfb277cc0
set%20property%20of%20null__explanation: d9448c7316667a30d2e527f2451f5a38
set%20property%20of%20null__why: 1f7d4c1ed46d91c725c6de62741a3078
set%20property%20of%20null__fix_0: d5064e99652eaaf448888de18a9aeecc
set%20property%20of%20null__fix_1: 90360192c140f7fa1c1ac4ac08c8a6fb
socket%20hang%20up__explanation: f1eb15fd5d6dd56b215010f70c6c7925
socket%20hang%20up__why: 613ac50490c0fb3191bed237208f856c
socket%20hang%20up__fix_0: 38c87939504c0049d35f221eb7c80d1c
socket%20hang%20up__fix_1: 7bf21183860ec1bbbcd7e86d40bf2a30
Unexpected%20end%20of%20JSON%20input__explanation: 6f9b0f41e69ff8ae722851041415bb7d
Unexpected%20end%20of%20JSON%20input__why: f8aa7923c3b17ffd1c0faf263aeb92c8
Unexpected%20end%20of%20JSON%20input__fix_0: 0b48d1cc085b9d697ce0d04a523583e3
Unexpected%20end%20of%20JSON%20input__fix_1: 19a9b4ddf3c0d32678ff7363518cdb49
Script%20execution%20timed%20out__explanation: 80e8c1aa98796e2f8311def28b83876a
Script%20execution%20timed%20out__why: 7e3d92573c0e438a11ad46c734ce3510
Script%20execution%20timed%20out__fix_0: 13f27f2b06ae02c841e19bac020d607e
Script%20execution%20timed%20out__fix_1: 30d7e8d779544fe82f5a70c6af2f2c8d
"'then'%20of%20undefined__explanation": a14ca654fb551e343a10dd891afe14eb
"'then'%20of%20undefined__why": b2d25ccfb11b1e69e94ea5ea00ac851f
"'then'%20of%20undefined__fix_0": 1ac24f8efda96671ca766a497076d894
"'then'%20of%20undefined__fix_1": 32c9b8bf21b7414f3a4ee3f27a76a3f1
Invalid%20connection%20string__explanation: 14f5626bf386c35fe9de5581fc100688
Invalid%20connection%20string__why: 069cf3455e03ba0b3d87b4b661cf9ec2
Invalid%20connection%20string__fix_0: 4644807643e2f6896f3ee4281a816cf9
window%20is%20not%20defined__explanation: 293ed55f0b8dc25a72351b48ed40d3c3
window%20is%20not%20defined__why: 2eadceb65ad81bec1e56a6a3cacbb0f3
window%20is%20not%20defined__fix_0: 50285071c28d41a09b5249cd265c9926
window%20is%20not%20defined__fix_1: ff5ae1c82709204024d602c4f62c9e9a
Too%20many%20listeners__explanation: c4d2550e8da00d7ed86ba3cf6107e86e
Too%20many%20listeners__why: c1cf9999ffcdce6c06a34d9a3588fe64
Too%20many%20listeners__fix_0: 51c39fae071228304bea30efe6179a3d
Too%20many%20listeners__fix_1: dc48ed601353286d7538bc2b8cad0e8c
spread%20non-iterable__explanation: ceefe3c1623f6d771bff87389b9e4471
spread%20non-iterable__why: 0a561a230bfe822fb0f1521593d5e42b
spread%20non-iterable__fix_0: a12639752eefe4017ab9b9f3aa6249e0
EPIPE__explanation: 6a0f8affc26e6a1e31c39c6f0c9f5299
EPIPE__why: 80bfe0493f10522a24778aa7813fed86
EPIPE__fix_0: c0927e6e1fe546043c38c79c159fff81
EPIPE__fix_1: 9c721f4d0c99d3c569a165cafeb8ceb3
Missing%20initializer__explanation: 57cab3b2824f7f523ce954c73c08cae9
Missing%20initializer__why: e35c7907e7aafa5400cf52a92095a30e
Missing%20initializer__fix_0: 98cb124fd77709758f9c1f181269a71d
peerinvalid__explanation: f8cc3ce3975aaaad41e88489622f7207
peerinvalid__why: bbb0b4f220e719245b675e33acbe1b3a
peerinvalid__fix_0: d8b40b19e44801ae7371b49d9b149264
filter%20is%20not%20a%20function__explanation: 2dd815ca2b86f48e4044b6820f59d28e
filter%20is%20not%20a%20function__why: 85411fccb964ee21650baad7486cc0d3
filter%20is%20not%20a%20function__fix_0: e6509aa36837dc615a1106e8b2102180
ENOTFOUND__explanation: 4f213ad0b9ac03cf2a24b3578f9fe6cb
ENOTFOUND__why: ef8f385a90ead39862cb4a2894f82361
ENOTFOUND__fix_0: 47afce4afbf3d8f5e33713a3689deabb
ENOTFOUND__fix_1: 89318ad17a3c3a08890cd215cb06e40d
reserved%20word__explanation: 4d4b3016ed00bd0f33a9a01bd65e5867
reserved%20word__why: be0507ac77678d6096d8b0be68a06406
reserved%20word__fix_0: bebeea5fb5dbc077b6e56f84c1e947d1
Cannot%20find%20name__explanation: 3ef4a0fdf0b67043dd087ec90004b4b0
Cannot%20find%20name__why: 10b078fba28fbb569048ffe78d143ef0
Cannot%20find%20name__fix_0: 7e5c2caf094f77d67b7da2ecf48617a8
Cannot%20find%20name__fix_1: a63770f64eeee222dd718b90a2c09b2e
convert%20undefined%20or%20null%20to%20object__explanation: eb0847b5e485bde6428b1daea4be33c1
convert%20undefined%20or%20null%20to%20object__why: 90953678308688d93af48a614a736efd
convert%20undefined%20or%20null%20to%20object__fix_0: 3376a40c0d55afec4eacadd92bb014f1
Access-Control-Allow-Origin__explanation: 7ab03605cdc9aa387f6d148d48687f86
Access-Control-Allow-Origin__why: e336ccba7c256cb4c931839ae176c5ce
Access-Control-Allow-Origin__fix_0: 0313f9a5eb29c38e3645bbf1dba08caa
Invalid%20or%20unexpected%20token__explanation: 7143746c889306fa441f10c2ea91cd30
Invalid%20or%20unexpected%20token__why: dcc4e55ed24b76aeb5580501792f6b30
Invalid%20or%20unexpected%20token__fix_0: 721a3691053419a44a4f32a6eededd9e
Invalid%20or%20unexpected%20token__fix_1: 166381222f0b86af2dd5729ccff6e542
timeout%20of%202000ms%20exceeded__explanation: 2d9a63a7c04bd0a94a789e61575a5d51
timeout%20of%202000ms%20exceeded__why: 0122d56fc40efda5d84d1267381e1393
timeout%20of%202000ms%20exceeded__fix_0: 04475d180de140134b159b35825fe66d
timeout%20of%202000ms%20exceeded__fix_1: 2345f28a91ce9d63c171a8e288a9fe91
does%20not%20exist%20on%20type__explanation: 4f31168b6bcbdc7cf233cc205de1fd11
does%20not%20exist%20on%20type__why: dbd3aad72f9c390a4a7b39613cd60371
does%20not%20exist%20on%20type__fix_0: 0f16abd8a1c5040b68cfae15baa886dd
does%20not%20exist%20on%20type__fix_1: 971355fffe0dc9e286af3836d7f9c854
npm%20ERR!%20404__explanation: 8d4b1708db44bc4f34120774e5e05783
npm%20ERR!%20404__why: 8db41b323b5bbbbaadfe8851c0c7dbe7
npm%20ERR!%20404__fix_0: 958e997b8e5dcea7a3f477415199f922
npm%20ERR!%20404__fix_1: 6aed2dda9753dc6b9a7db6bee2da3a7f
Unexpected%20end%20of%20input__explanation: 9adc4a9073ebb8fac3c0c93b100f88ef
Unexpected%20end%20of%20input__why: dfbb540307ab05b9fa252b007fa4f940
Unexpected%20end%20of%20input__fix_0: 84909eef8d62e870da26b9bebce44df8
Unexpected%20end%20of%20input__fix_1: 3441fd4ff396e1299156e4a887c2c8d0
Unexpected%20end%20of%20input__fix_2: 7fa94f53fa73a8283ac2c5b68fd03763
missing%20)%20after%20argument%20list__explanation: bc01bb743ae3354e6e7b090584d789c6
missing%20)%20after%20argument%20list__why: 5d2c1d927a96c1e67ace72b448653625
missing%20)%20after%20argument%20list__fix_0: 19a4b63b4aa7213e762134f4cf7cdb7d
missing%20)%20after%20argument%20list__fix_1: d2e96f3e7fbdb91fe002dd7a446bce37
39 changes: 36 additions & 3 deletions lib/matcher.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,46 @@
const database = require("./database.json");
const fs = require('fs')
const path = require("path");

function findError(input) {
// Loading the locale file
function loadLocale(lang = "en"){
const filepath = path.join(__dirname,"../locales", `${lang}.json`);
const fallback = path.join(__dirname,"../locales/en.json");
try {
return JSON.parse(fs.readFileSync(filepath,"utf8"))
} catch (error) {
return JSON.parse(fs.readFileSync(fallback,"utf8"))

}
}

//this function will translate every single entry using the loaded locals
function translateEntry(entry,locale){
const key = entry.match
return{
...entry,
explanation:locale[`${key}__explanation`] || entry.explanation,
why: locale[`${key}__why`] || entry.why,
fixes: entry.fixes.map(
(fix,i) =>locale[`${key}__fix_${i}`] || fix
)
}
}


function findError(input,lang = "en") {

if (!input) return { count: 0, matches: [] };

if (typeof input !== "string") input = String(input);

// 1. Normalize the input (Lowercase and remove extra whitespace)
const lowerInput = input.toLowerCase();



const locale = loadLocale(lang) // I'm calling the load local file here

//untouched
// 2. Filter the database
let foundMatches = database.filter(entry => {
const matchPhrase = entry.match.toLowerCase();
Expand All @@ -28,7 +61,7 @@ function findError(input) {

for (const match of foundMatches) {
if (!seenNames.has(match.name)) {
uniqueMatches.push(match);
uniqueMatches.push(translateEntry(match,locale));
seenNames.add(match.name);
}
}
Expand Down
Loading
Loading