Skip to content

Commit 7824bc0

Browse files
joyeecheungpriyank-p
authored andcommitted
ci: handle 404 responses
1 parent 94a7193 commit 7824bc0

File tree

2 files changed

+97
-21
lines changed

2 files changed

+97
-21
lines changed

lib/ci/ci_failure_parser.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ const JS_TEST_FAILURE = 'JS_TEST_FAILURE';
3232
const CC_TEST_FAILURE = 'CC_TEST_FAILURE';
3333
const JENKINS_FAILURE = 'JENKINS_FAILURE';
3434
const GIT_FAILURE = 'GIT_FAILURE';
35+
const NCU_FAILURE = 'NCU_FAILURE';
3536

3637
const FAILURE_TYPES = {
3738
BUILD_FAILURE, JS_TEST_FAILURE, CC_TEST_FAILURE,
38-
JENKINS_FAILURE, GIT_FAILURE
39+
JENKINS_FAILURE, GIT_FAILURE, NCU_FAILURE
3940
};
4041

4142
class CIResult {
@@ -93,6 +94,15 @@ class GitFailure extends CIResult {
9394
}
9495
}
9596

97+
// Failures in this tool, we wrap them to avoid exceptions when
98+
// walking the CI
99+
class NCUFailure extends CIResult {
100+
constructor(ctx, reason) {
101+
super(ctx, reason);
102+
this.type = NCU_FAILURE;
103+
}
104+
}
105+
96106
function failureMatcher(Failure, patterns, ctx, text) {
97107
for (const pattern of patterns) {
98108
const matches = text.match(pattern.pattern);
@@ -251,14 +261,16 @@ CIFailureParser.FAILURE_CONSTRUCTORS = {
251261
JENKINS_FAILURE: JenkinsFailure,
252262
JS_TEST_FAILURE: JSTestFailure,
253263
CC_TEST_FAILURE: CCTestFailure,
254-
GIT_FAILURE: GitFailure
264+
GIT_FAILURE: GitFailure,
265+
NCU_FAILURE: NCUFailure
255266
};
256267
CIFailureParser.CIResult = CIResult;
257268
CIFailureParser.FAILURE_TYPES_NAME = {
258269
BUILD_FAILURE: 'Build Failure',
259270
JENKINS_FAILURE: 'Jenkins Failure',
260271
JS_TEST_FAILURE: 'JSTest Failure',
261272
CC_TEST_FAILURE: 'CCTest Failure',
262-
GIT_FAILURE: 'Git Failure'
273+
GIT_FAILURE: 'Git Failure',
274+
NCU_FAILURE: 'node-core-utils failure'
263275
};
264276
module.exports = CIFailureParser;

lib/ci/ci_result_parser.js

Lines changed: 82 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ const Cache = require('../cache');
77
const CIFailureParser = require('./ci_failure_parser');
88
const {
99
FAILURE_TYPES: {
10-
BUILD_FAILURE
10+
BUILD_FAILURE,
11+
NCU_FAILURE
1112
},
1213
FAILURE_CONSTRUCTORS: {
13-
[BUILD_FAILURE]: BuildFailure
14+
[BUILD_FAILURE]: BuildFailure,
15+
[NCU_FAILURE]: NCUFailure
1416
},
1517
CIResult,
1618
FAILURE_TYPES_NAME
@@ -148,19 +150,28 @@ class Job {
148150
}
149151

150152
async parseConsoleText() {
151-
const text = await this.getConsoleText();
152-
const parser = new CIFailureParser(this, text);
153-
const results = parser.parse();
153+
let text;
154+
try {
155+
text = await this.getConsoleText();
156+
} catch (err) {
157+
this.failures = [
158+
new NCUFailure({
159+
url: this.consoleUrl, builtOn: this.builtOn
160+
}, err.message)
161+
];
162+
return this.failures;
163+
}
154164

155-
if (results) {
156-
this.failures = results;
157-
return results;
165+
const parser = new CIFailureParser(this, text);
166+
let results = parser.parse();
167+
if (!results) {
168+
results = [
169+
new CIResult({ url: this.jobUrl, builtOn: this.builtOn }, 'Unknown')
170+
];
158171
}
159172

160-
this.failures = [
161-
new CIResult({ url: this.jobUrl, builtOn: this.builtOn }, 'Unknown')
162-
];
163-
return this.failures;
173+
this.failures = results;
174+
return results;
164175
}
165176
}
166177

@@ -505,8 +516,16 @@ class CommitBuild extends TestBuild {
505516
// Get the failures and their reasons of this build
506517
async getResults(data) {
507518
const { path, cli, request } = this;
519+
508520
if (!data) {
509-
data = await this.getBuildData();
521+
try {
522+
data = await this.getBuildData();
523+
} catch (err) {
524+
this.failures = [
525+
new NCUFailure({ url: this.apiUrl }, err.message)
526+
];
527+
return this.failures;
528+
}
510529
}
511530
this.setBuildData(data);
512531
// No builds at all
@@ -562,7 +581,16 @@ class PRBuild extends TestBuild {
562581
// Get the failures and their reasons of this build
563582
async getResults() {
564583
const { cli, request } = this;
565-
const data = await this.getBuildData();
584+
585+
let data;
586+
try {
587+
data = await this.getBuildData();
588+
} catch (err) {
589+
this.failures = [
590+
new NCUFailure({ url: this.apiUrl }, err.message)
591+
];
592+
return this.failures;
593+
}
566594
const {
567595
result, subBuilds, changeSet, actions, timestamp
568596
} = data;
@@ -661,7 +689,16 @@ class FannedBuild extends Job {
661689
// Get the failures and their reasons of this build
662690
async getResults() {
663691
const { cli, request } = this;
664-
const data = await this.getAPIData();
692+
693+
let data;
694+
try {
695+
data = await this.getAPIData();
696+
} catch (err) {
697+
this.failures = [
698+
new NCUFailure({ url: this.apiUrl }, err.message)
699+
];
700+
return this.failures;
701+
}
665702
this.builtOn = data.builtOn;
666703

667704
if (!data.subBuilds.length) {
@@ -707,7 +744,15 @@ class LinterBuild extends Job {
707744
}
708745

709746
async getResults() {
710-
const data = await this.getAPIData();
747+
let data;
748+
try {
749+
data = await this.getAPIData();
750+
} catch (err) {
751+
this.failures = [
752+
new NCUFailure(this, err.message)
753+
];
754+
return this.failures;
755+
}
711756
this.builtOn = data.builtOn;
712757
return this.parseConsoleText();
713758
}
@@ -725,7 +770,18 @@ class NormalBuild extends Job {
725770

726771
async getResults() {
727772
const { cli, request } = this;
728-
const { result, runs, builtOn } = await this.getAPIData();
773+
774+
let data;
775+
try {
776+
data = await this.getAPIData();
777+
} catch (err) {
778+
this.failures = [
779+
new NCUFailure({ url: this.apiUrl }, err.message)
780+
];
781+
return this.failures;
782+
}
783+
784+
const { result, runs, builtOn } = data;
729785
this.builtOn = builtOn;
730786

731787
if (result !== FAILURE) {
@@ -782,7 +838,15 @@ class TestRun extends Job {
782838
}
783839

784840
async getData() {
785-
const data = await this.getAPIData();
841+
let data;
842+
try {
843+
data = await this.getAPIData();
844+
} catch (err) {
845+
this.failures = [
846+
new NCUFailure({ url: this.apiUrl }, err.message)
847+
];
848+
return this.failures;
849+
}
786850
if (data.actions && data.actions.find(item => item.causes)) {
787851
const actions = data.actions.find(item => item.causes);
788852
this.cause = actions.causes[0];

0 commit comments

Comments
 (0)