Skip to content

Commit

Permalink
Merge pull request #5231 from Shopify/01-17-rethrow_functions_esbuild…
Browse files Browse the repository at this point in the history
…_errors

Rethrow functions esbuild errors
  • Loading branch information
isaacroldan authored Jan 21, 2025
2 parents 28cfaea + 8938052 commit 850358c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/app/src/cli/services/build/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,16 @@ export async function buildFunctionExtension(
await touchFile(bundlePath)
await writeFile(bundlePath, base64Contents)
}
} catch (error) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
// We capture and rethrow as AbortError to avoid random user-code errors being reported as CLI bugs.
// At the same time, we need to keep the ESBuild details for the logs. (the `errors` array)
const errorMessage = (error as Error).message ?? 'Unknown error occurred'
throw new AbortError('Failed to build function.', errorMessage)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const newError: any = new AbortError('Failed to build function.', errorMessage)
// Inject ESBuild errors if present
newError.errors = error.errors
throw newError
} finally {
await releaseLock()
}
Expand Down

0 comments on commit 850358c

Please sign in to comment.