@@ -3,6 +3,14 @@ import { exec } from "./shell";
3
3
4
4
let werft : Werft ;
5
5
6
+ export class FailedSliceError extends Error {
7
+ constructor ( message : string ) {
8
+ super ( message ) ;
9
+ this . name = "FailedSliceError" ;
10
+ Object . setPrototypeOf ( this , FailedSliceError . prototype ) ;
11
+ }
12
+ }
13
+
6
14
/**
7
15
* For backwards compatibility with existing code we expose a global Werft instance
8
16
*/
@@ -75,7 +83,7 @@ export class Werft {
75
83
/**
76
84
* Use this when you intend to fail the werft job
77
85
*/
78
- public fail ( slice , err ) {
86
+ public fail ( slice : string , err : string | Error ) {
79
87
const span = this . sliceSpans [ slice ] ;
80
88
81
89
if ( span ) {
@@ -84,6 +92,8 @@ export class Werft {
84
92
console . log ( `[${ slice } ] tracing warning: No slice span by name ${ slice } ` ) ;
85
93
}
86
94
95
+ const errorMessage = err instanceof Error ? err . toString ( ) : err ;
96
+
87
97
// Set the status on the span for the slice and also propagate the status to the phase and root span
88
98
// as well so we can query on all phases that had an error regardless of which slice produced the error.
89
99
[ span , this . rootSpan , this . currentPhaseSpan ] . forEach ( ( span : Span ) => {
@@ -92,12 +102,17 @@ export class Werft {
92
102
}
93
103
span . setStatus ( {
94
104
code : SpanStatusCode . ERROR ,
95
- message : err ,
105
+ message : errorMessage ,
96
106
} ) ;
97
107
} ) ;
98
108
99
- console . log ( `[${ slice } |FAIL] ${ err } ` ) ;
100
- throw err ;
109
+ // In case the error message is a multi-line string we want to ensure that we contain
110
+ // the error message within the slice (otherwise they'll be moved to the "default" slice of the phase)
111
+ errorMessage . split ( "\n" ) . forEach ( ( line : string ) => console . log ( `[${ slice } ] ${ line } ` ) ) ;
112
+
113
+ console . log ( `[${ slice } ] Failed. Expand to see why` ) ;
114
+ console . log ( `[${ slice } |FAIL]` ) ;
115
+ throw new FailedSliceError ( slice ) ;
101
116
}
102
117
103
118
/**
0 commit comments