1
+ import { strict as assert } from "assert" ;
1
2
import type { CleanupOptions } from "faastjs" ;
3
+ import { FaastError } from "faastjs" ;
2
4
import { promises as fs } from "fs" ;
3
5
import pSettled from "p-settle" ;
4
6
import path from "path" ;
5
7
import recursive from "recursive-readdir" ;
6
8
import { assertString } from "../assert.js" ;
7
9
import { resultInfoLogType } from "../cli.js" ;
8
- import type { CompilerError } from "../compiler.js" ;
10
+ import type * as compilerCoreFunctions from "../compiler-core .js" ;
9
11
import {
12
+ CompilerError ,
10
13
compileToJson ,
11
14
createCompilerOptionsForChunks ,
12
15
createCompilerOptionsForPage ,
13
16
} from "../compiler.js" ;
14
- import type * as compilerCoreFunctions from "../compiler-core.js" ;
15
17
import type { DuckConfig } from "../duckconfig.js" ;
16
18
import type { EntryConfig } from "../entryconfig.js" ;
17
19
import { loadEntryConfig } from "../entryconfig.js" ;
@@ -147,7 +149,7 @@ async function waitAllAndThrowIfAnyCompilationsFailed(
147
149
} ;
148
150
}
149
151
// has some errors
150
- const reason = result . reason as CompilerError ;
152
+ const reason = result . reason as any ;
151
153
try {
152
154
const { command, items } = parseErrorReason ( reason , config ) ;
153
155
return {
@@ -167,11 +169,25 @@ async function waitAllAndThrowIfAnyCompilationsFailed(
167
169
return reasons ;
168
170
169
171
function parseErrorReason (
170
- reason : CompilerError & { info ?: Record < string , any > } ,
172
+ reason : any ,
171
173
config : DuckConfig
172
174
) : { command : string ; items : CompileErrorItem [ ] } {
173
- const { message : stderr , info } = reason ;
174
- const message = config . batch && info ? info . message : stderr ;
175
+ let message : string ;
176
+ if ( config . batch ) {
177
+ assert ( reason instanceof FaastError ) ;
178
+ assert . equal ( reason . name , "CompilerError" ) ;
179
+ // In batch mode, faast.js surrounds an error with a FaastError that
180
+ // is a subclass of VError. `.jse_shortmsg` is a property of VError for
181
+ // debug. The original error message is only stored this prop.
182
+ // `.message` is transformed into a string concatenated with `cause`,
183
+ // so it cannot be used.
184
+ // https://github.com/TritonDataCenter/node-verror/blob/v1.10.1/lib/verror.js#L167-L172
185
+ message = ( reason as any ) . jse_shortmsg ;
186
+ } else if ( reason instanceof CompilerError ) {
187
+ message = reason . message ;
188
+ } else {
189
+ throw new TypeError ( `reason is an unexpected error` ) ;
190
+ }
175
191
const [ command , , ...messages ] = message . split ( "\n" ) ;
176
192
return { command, items : JSON . parse ( messages . join ( "\n" ) ) } ;
177
193
}
0 commit comments