Skip to content

Commit adcb910

Browse files
committed
feat: better logs
1 parent 5c16829 commit adcb910

File tree

5 files changed

+101
-42
lines changed

5 files changed

+101
-42
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bin/* linguist-generated

CHANGELOG.md

+4
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+
### Changed
10+
11+
- improving error reporting for debugging purposes
12+
913
## [0.12.0] - 2024-02-02
1014

1115
### Added

bin/index.js

+54-32
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

+41-9
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ import {
33
error,
44
getBooleanInput,
55
getInput,
6+
info,
67
setFailed,
78
summary,
89
} from "@actions/core";
910
import { getOctokit } from "@actions/github";
1011
import { context } from "@actions/github/lib/utils";
1112
import { existsSync, readFile } from "fs";
1213
import { promisify } from "util";
14+
import { RequestError } from "@octokit/request-error";
1315

1416
import { chart } from "./chart";
1517
import { fromString } from "./clover";
@@ -186,6 +188,21 @@ function* checkThreshold(c: Stats, o?: Stats) {
186188
}
187189
}
188190

191+
const scopesToString = (scopes: null | string) =>
192+
scopes?.split(/,\s+/)?.join(", ") || "(empty)";
193+
194+
const errorToString = (e: any) =>
195+
e +
196+
(e instanceof Error
197+
? (e instanceof RequestError
198+
? `\nRequest: ${e.request.method} ${e.request.url}` +
199+
`\nResponse Scopes: ${scopesToString(
200+
e.response?.headers?.["x-oauth-scopes"]
201+
)}` +
202+
`\nResponse Headers: ${JSON.stringify(e.response?.headers || [])}`
203+
: "") + `\nStack: ${e.stack}`
204+
: "");
205+
189206
const notFoundMessage =
190207
"was not found, please check if the path is valid, or if it exists.";
191208

@@ -273,8 +290,15 @@ ${signature}`;
273290
const u = await github.rest.users.getAuthenticated();
274291
filter = (c: any) => c?.user?.login === u.data.login;
275292

276-
debug("Using a PAT from " + u.data.login);
277-
} catch (e) {}
293+
info(
294+
"Using a PAT from " +
295+
u.data.login +
296+
" with scopes: " +
297+
scopesToString(u.headers?.["x-oauth-scopes"])
298+
);
299+
} catch (e) {
300+
debug(errorToString(e));
301+
}
278302

279303
let commentId = null;
280304
try {
@@ -291,7 +315,7 @@ ${signature}`;
291315
commentId = c.id;
292316
}
293317
} catch (e) {
294-
error(e);
318+
error(errorToString(e));
295319
}
296320

297321
if (commentId) {
@@ -305,11 +329,19 @@ ${signature}`;
305329
} catch {}
306330
}
307331

308-
await github.rest.issues.createComment({
309-
...context.repo,
310-
issue_number: context.issue.number,
311-
body,
312-
});
332+
await github.rest.issues
333+
.createComment({
334+
...context.repo,
335+
issue_number: context.issue.number,
336+
body,
337+
})
338+
.catch((e: Error) => {
339+
throw new Error(
340+
"Failed to create a new comment with: " +
341+
e.message +
342+
(e.stack ? ". Stack: " + e.stack : "")
343+
);
344+
});
313345
};
314346

315-
run().catch((err: Error) => setFailed(err + " Stack: " + err.stack));
347+
run().catch((err: Error) => setFailed(errorToString(err)));

0 commit comments

Comments
 (0)