diff --git a/.changeset/rare-ants-swim.md b/.changeset/rare-ants-swim.md new file mode 100644 index 0000000000..1bde7bf142 --- /dev/null +++ b/.changeset/rare-ants-swim.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Improves errors in certain places to also report their causes. diff --git a/packages/astro/src/assets/build/generate.ts b/packages/astro/src/assets/build/generate.ts index 4ee210ec30..a73ef11f27 100644 --- a/packages/astro/src/assets/build/generate.ts +++ b/packages/astro/src/assets/build/generate.ts @@ -226,7 +226,6 @@ export async function generateImagesForPath( ...AstroErrorData.CouldNotTransformImage, message: AstroErrorData.CouldNotTransformImage.message(originalFilePath), }, - undefined, { cause: e } ); diff --git a/packages/astro/src/core/errors/errors.ts b/packages/astro/src/core/errors/errors.ts index faf3656869..31e3be5202 100644 --- a/packages/astro/src/core/errors/errors.ts +++ b/packages/astro/src/core/errors/errors.ts @@ -38,10 +38,10 @@ export class AstroError extends Error { type: ErrorTypes = 'AstroError'; - constructor(props: ErrorProperties, ...params: any) { - super(...params); - + constructor(props: ErrorProperties, options?: ErrorOptions) { const { name, title, message, stack, location, hint, frame } = props; + super(message, options); + this.title = title; this.name = name; @@ -81,8 +81,8 @@ export class AstroError extends Error { export class CompilerError extends AstroError { type: ErrorTypes = 'CompilerError'; - constructor(props: ErrorProperties, ...params: any) { - super(props, ...params); + constructor(props: ErrorProperties, options?: ErrorOptions) { + super(props, options); } static is(err: unknown): err is CompilerError { @@ -120,8 +120,8 @@ export class AggregateError extends AstroError { // Despite being a collection of errors, AggregateError still needs to have a main error attached to it // This is because Vite expects every thrown errors handled during HMR to be, well, Error and have a message - constructor(props: ErrorProperties & { errors: AstroError[] }, ...params: any) { - super(props, ...params); + constructor(props: ErrorProperties & { errors: AstroError[] }, options?: ErrorOptions) { + super(props, options); this.errors = props.errors; } diff --git a/packages/astro/src/core/middleware/loadMiddleware.ts b/packages/astro/src/core/middleware/loadMiddleware.ts index 135f7fbc47..da60909826 100644 --- a/packages/astro/src/core/middleware/loadMiddleware.ts +++ b/packages/astro/src/core/middleware/loadMiddleware.ts @@ -12,7 +12,7 @@ export async function loadMiddleware(moduleLoader: ModuleLoader) { try { return await moduleLoader.import(MIDDLEWARE_MODULE_ID); } catch (error: any) { - const astroError = new AstroError(MiddlewareCantBeLoaded, undefined, { cause: error }); + const astroError = new AstroError(MiddlewareCantBeLoaded, { cause: error }); throw astroError; } }