-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
44 lines (40 loc) · 1.15 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// istanbul ignore file - All tests for this are in run.ts
import { run } from "./run";
import { NoWorkflowError } from "./getWorkflow";
import { parseArgs } from "./parseArgs";
function viewBranch(error) {
if (error.branch) {
console.log(
`Check out the pipeline here: https://app.circleci.com/pipelines/${process.env.PROJECT_SLUG}?branch=${error.branch}&filter=all`
);
}
}
process.on("uncaughtException", function (err) {
console.error("Uncaught exception! Stack was:");
console.error(err.stack);
viewBranch(err);
});
process.on("unhandledRejection", function (error) {
console.error("Unhandled Promise Rejection:");
console.error(error);
viewBranch(error);
});
try {
const args = parseArgs();
run({
fetchInterval: 5,
...args,
});
} catch (error) {
if (error instanceof NoWorkflowError) {
const tenSeconds = 10000;
// Re-try with a 10s delay to let the pipeline finish loading
setTimeout(() => {
run({
fetchInterval: 5,
});
}, tenSeconds);
} else {
console.error("Error caught: ", error);
}
}