Skip to content

Commit

Permalink
[ci] format
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp authored and astrobot-houston committed Dec 14, 2023
1 parent e1a5a2d commit d234005
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
4 changes: 2 additions & 2 deletions packages/astro/src/core/errors/errors-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1299,5 +1299,5 @@ export const UnhandledRejection = {
message: (stack: string) => {
return `Astro detected an unhandled rejection. Here's the stack trace:\n${stack}`;
},
hint: 'Make sure your promises all have an `await` or a `.catch()` handler.'
}
hint: 'Make sure your promises all have an `await` or a `.catch()` handler.',
};
11 changes: 8 additions & 3 deletions packages/astro/src/vite-plugin-astro-server/error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ModuleLoader } from '../core/module-loader/index.js'
import type { ModuleLoader } from '../core/module-loader/index.js';
import type { AstroConfig } from '../@types/astro.js';
import type DevPipeline from './devPipeline.js';

Expand All @@ -7,7 +7,12 @@ import { createSafeError } from '../core/errors/index.js';
import { formatErrorMessage } from '../core/messages.js';
import { eventError, telemetry } from '../events/index.js';

export function recordServerError(loader: ModuleLoader, config: AstroConfig, pipeline: DevPipeline, _err: unknown) {
export function recordServerError(
loader: ModuleLoader,
config: AstroConfig,
pipeline: DevPipeline,
_err: unknown
) {
const err = createSafeError(_err);

// This could be a runtime error from Vite's SSR module, so try to fix it here
Expand All @@ -28,6 +33,6 @@ export function recordServerError(loader: ModuleLoader, config: AstroConfig, pip

return {
error: err,
errorWithMetadata
errorWithMetadata,
};
}
9 changes: 6 additions & 3 deletions packages/astro/src/vite-plugin-astro-server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,18 @@ export default function createVitePluginAstroServer({
function handleUnhandledRejection(rejection: any) {
const error = new AstroError({
...AstroErrorData.UnhandledRejection,
message: AstroErrorData.UnhandledRejection.message(rejection?.stack || rejection)
message: AstroErrorData.UnhandledRejection.message(rejection?.stack || rejection),
});
const store = localStorage.getStore();
if(store instanceof IncomingMessage) {
if (store instanceof IncomingMessage) {
const request = store;
setRouteError(controller.state, request.url!, error);
}
const { errorWithMetadata } = recordServerError(loader, settings.config, pipeline, error);
setTimeout(async () => loader.webSocketSend(await getViteErrorPayload(errorWithMetadata)), 200)
setTimeout(
async () => loader.webSocketSend(await getViteErrorPayload(errorWithMetadata)),
200
);
}

process.on('unhandledRejection', handleUnhandledRejection);
Expand Down

0 comments on commit d234005

Please sign in to comment.