Skip to content

Commit 12a1181

Browse files
authored
fix: clear message when clover file is not found (#22)
1 parent ef0717e commit 12a1181

File tree

5 files changed

+31
-7
lines changed

5 files changed

+31
-7
lines changed

.github/workflows/example.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ jobs:
1010
- name: Checkout code
1111
uses: actions/checkout@master
1212

13+
- name: clover file not found
14+
uses: ./.
15+
continue-on-error: true
16+
with:
17+
dir-prefix: /var/www/html
18+
file: not.found.xml
19+
base-file: not.found.too.xml
20+
signature: "file not found"
21+
1322
- name: clover file to comment (clover.example.xml)
1423
uses: ./.
1524
with:

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
### Fixed
10+
11+
- action was "panicking" when the `file` with the coverage was not found, a clearer message is shown now.
12+
913
## [0.7.0] - 2022-10-21
1014

1115
### Changed

bin/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89630,6 +89630,7 @@ function checkThreshold(c, o) {
8963089630
}
8963189631
});
8963289632
}
89633+
var notFoundMessage = "was not found, please check if the path is valid, or if it exists.";
8963389634
var run = function () { return __awaiter$1(void 0, void 0, void 0, function () {
8963489635
var commit, cStats, _a, oldStats, _b, _c, msgs, body, _d, _e, commentId, comments, i, c, e_1;
8963589636
var _g, _h, _j;
@@ -89645,12 +89646,15 @@ var run = function () { return __awaiter$1(void 0, void 0, void 0, function () {
8964589646
if (!context.payload.pull_request)
8964689647
return [2 /*return*/];
8964789648
commit = (_g = context.payload.pull_request) === null || _g === void 0 ? void 0 : _g.head.sha.substring(0, 7);
89649+
if (!require$$0$1.existsSync(file)) {
89650+
throw "file \"".concat(file, "\" ").concat(notFoundMessage);
89651+
}
8964889652
_a = fromString;
8964989653
return [4 /*yield*/, require$$6.promisify(require$$0$1.readFile)(file)];
8965089654
case 1:
8965189655
cStats = _a.apply(void 0, [(_k.sent()).toString()]);
8965289656
if (baseFile && !require$$0$1.existsSync(baseFile)) {
89653-
coreExports.error("file ".concat(baseFile, " was not found"));
89657+
coreExports.error("base file \"".concat(baseFile, "\" ").concat(notFoundMessage));
8965489658
baseFile = undefined;
8965589659
}
8965689660
_b = baseFile;
@@ -89686,7 +89690,7 @@ var run = function () { return __awaiter$1(void 0, void 0, void 0, function () {
8968689690
return [3 /*break*/, 8];
8968789691
case 7:
8968889692
e_1 = _k.sent();
89689-
console.error(e_1);
89693+
coreExports.error(e_1);
8969089694
return [3 /*break*/, 8];
8969189695
case 8:
8969289696
if (!commentId) return [3 /*break*/, 12];
@@ -89707,5 +89711,5 @@ var run = function () { return __awaiter$1(void 0, void 0, void 0, function () {
8970789711
}
8970889712
});
8970989713
}); };
89710-
run();
89714+
run()["catch"](coreExports.setFailed);
8971189715
//# sourceMappingURL=index.js.map

bin/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ function* checkThreshold(c: Stats, o?: Stats) {
123123
}
124124
}
125125

126+
const notFoundMessage =
127+
"was not found, please check if the path is valid, or if it exists.";
128+
126129
const run = async () => {
127130
if (!["lines", "methods", "branchs"].includes(tableWithTypeLimit)) {
128131
error(`there is no coverage type ${tableWithTypeLimit}`);
@@ -134,10 +137,14 @@ const run = async () => {
134137

135138
const commit = context.payload.pull_request?.head.sha.substring(0, 7);
136139

140+
if (!existsSync(file)) {
141+
throw `file "${file}" ${notFoundMessage}`;
142+
}
143+
137144
const cStats = fromString((await promisify(readFile)(file)).toString());
138145

139146
if (baseFile && !existsSync(baseFile)) {
140-
error(`file ${baseFile} was not found`);
147+
error(`base file "${baseFile}" ${notFoundMessage}`);
141148
baseFile = undefined;
142149
}
143150

@@ -174,7 +181,7 @@ ${signature}`;
174181
commentId = c.id;
175182
}
176183
} catch (e) {
177-
console.error(e);
184+
error(e);
178185
}
179186

180187
if (commentId) {
@@ -195,4 +202,4 @@ ${signature}`;
195202
});
196203
};
197204

198-
run();
205+
run().catch(setFailed);

0 commit comments

Comments
 (0)