0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

chore: improve type fidelity for internal error class (#9478)

* chore: improve type fidelity for internal error class

* add changeset

* simplify

* fix: adjust for new error

---------

Co-authored-by: Princesseuh <3019731+Princesseuh@users.noreply.github.com>
This commit is contained in:
Arsh 2023-12-20 21:13:50 +00:00 committed by GitHub
parent 60dc8da71b
commit dfef925e1f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 9 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Improves errors in certain places to also report their causes.

View file

@ -226,7 +226,6 @@ export async function generateImagesForPath(
...AstroErrorData.CouldNotTransformImage,
message: AstroErrorData.CouldNotTransformImage.message(originalFilePath),
},
undefined,
{ cause: e }
);

View file

@ -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;
}

View file

@ -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;
}
}