Skip to content

Commit

Permalink
chore: improve type fidelity for internal error class (#9478)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
lilnasy and Princesseuh committed Dec 20, 2023
1 parent 60dc8da commit dfef925
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/rare-ants-swim.md
@@ -0,0 +1,5 @@
---
'astro': patch
---

Improves errors in certain places to also report their causes.
1 change: 0 additions & 1 deletion packages/astro/src/assets/build/generate.ts
Expand Up @@ -226,7 +226,6 @@ export async function generateImagesForPath(
...AstroErrorData.CouldNotTransformImage,
message: AstroErrorData.CouldNotTransformImage.message(originalFilePath),
},
undefined,
{ cause: e }
);

Expand Down
14 changes: 7 additions & 7 deletions packages/astro/src/core/errors/errors.ts
Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/middleware/loadMiddleware.ts
Expand Up @@ -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;
}
}

0 comments on commit dfef925

Please sign in to comment.