Skip to content

Commit 9edd6a2

Browse files
pranaygpclaude
andcommitted
refactor: improve error handling in bundle creation
Enhances logEsbuildMessages to throw on critical errors by default, ensuring build failures are properly surfaced instead of being silently logged. Changes: - Added throwOnError parameter to logEsbuildMessages (defaults to true) - When errors occur, now throws with formatted error messages - Collects all error messages and locations for comprehensive error reporting This prevents builds from appearing successful when esbuild encounters critical errors, improving debugging and build reliability. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent bfd4924 commit 9edd6a2

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@workflow/builders": patch
3+
---
4+
5+
Improve error handling in bundle creation methods

packages/builders/src/base-builder.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,20 +179,33 @@ export abstract class BaseBuilder {
179179
}
180180
}
181181

182+
/**
183+
* Logs and optionally throws on esbuild errors and warnings.
184+
* @param throwOnError - If true, throws an error when esbuild errors are present
185+
*/
182186
private logEsbuildMessages(
183187
result: { errors?: any[]; warnings?: any[] },
184-
phase: string
188+
phase: string,
189+
throwOnError = true
185190
): void {
186191
if (result.errors && result.errors.length > 0) {
187192
console.error(`❌ esbuild errors in ${phase}:`);
193+
const errorMessages: string[] = [];
188194
for (const error of result.errors) {
189195
console.error(` ${error.text}`);
196+
errorMessages.push(error.text);
190197
if (error.location) {
191-
console.error(
192-
` at ${error.location.file}:${error.location.line}:${error.location.column}`
193-
);
198+
const location = ` at ${error.location.file}:${error.location.line}:${error.location.column}`;
199+
console.error(location);
200+
errorMessages.push(location);
194201
}
195202
}
203+
204+
if (throwOnError) {
205+
throw new Error(
206+
`Build failed during ${phase}:\n${errorMessages.join('\n')}`
207+
);
208+
}
196209
}
197210

198211
if (result.warnings && result.warnings.length > 0) {

0 commit comments

Comments
 (0)