Skip to content

Commit

Permalink
feat: add readme for error hint (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
gemwuu authored Sep 6, 2022
1 parent 727ea1a commit af5bf32
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"typescript": "^4.7.4"
},
"engines": {
"node": ">=14.20.0"
"node": ">=14.17.0"
},
"repository": {
"type": "git",
Expand Down
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ class ErrorRunner {
});

message = `${this.getPrefix(loglevel, code)}${message}`;

if (error.readme) {
message = `${message}\n${this.getPrefix(loglevel, code)}参考文档,了解更多:${error.readme}`;
}
return message;
}

Expand Down
2 changes: 1 addition & 1 deletion test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe('test/index.test.ts', () => {
const { code, message } = new Error1();
await errorRunner.precheck(code, message);
const errHint = await errorRunner.generate(code, message);
assert.strictEqual(errHint, '[@cnpmjs/errors]E02001: 当前运行 Node 版本为 v14.20.0');
assert.strictEqual(errHint, '[@cnpmjs/errors]E02001: 当前运行 Node 版本为 v14.20.0\n[@cnpmjs/errors]E02001: 参考文档,了解更多:aaa');
});
});

Expand Down

0 comments on commit af5bf32

Please sign in to comment.