@@ -7,10 +7,12 @@ const Cache = require('../cache');
77const CIFailureParser = require ( './ci_failure_parser' ) ;
88const {
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