Skip to content

Commit 850358c

Browse files
authored
Merge pull request #5231 from Shopify/01-17-rethrow_functions_esbuild_errors
Rethrow functions esbuild errors
2 parents 28cfaea + 8938052 commit 850358c

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

packages/app/src/cli/services/build/extension.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,16 @@ export async function buildFunctionExtension(
186186
await touchFile(bundlePath)
187187
await writeFile(bundlePath, base64Contents)
188188
}
189-
} catch (error) {
189+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
190+
} catch (error: any) {
191+
// We capture and rethrow as AbortError to avoid random user-code errors being reported as CLI bugs.
192+
// At the same time, we need to keep the ESBuild details for the logs. (the `errors` array)
190193
const errorMessage = (error as Error).message ?? 'Unknown error occurred'
191-
throw new AbortError('Failed to build function.', errorMessage)
194+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
195+
const newError: any = new AbortError('Failed to build function.', errorMessage)
196+
// Inject ESBuild errors if present
197+
newError.errors = error.errors
198+
throw newError
192199
} finally {
193200
await releaseLock()
194201
}

0 commit comments

Comments
 (0)