Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 28 additions & 20 deletions packages/platform/src/Platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,16 @@ import {
HttpServerResponse,
} from "@effect/platform";
import type { RouteNotFound } from "@effect/platform/HttpServerError";
import { Data, Effect, Layer, Record, Ref, Schema, Scope } from "effect";
import {
Console,
Data,
Effect,
Layer,
Record,
Ref,
Schema,
Scope,
} from "effect";

import {
AsyncCache,
Expand Down Expand Up @@ -487,12 +496,14 @@ export const toHttpRoutes = <

// Register GET handler with error logging
const debugHandler = catchRedirects(getHandler).pipe(
Effect.catchAllCause((cause) => {
console.error(`[Platform] Error handling GET ${path}:`, cause);
return Effect.succeed(
HttpServerResponse.text(`Internal Server Error`, { status: 500 }),
);
}),
Effect.catchAllCause((cause) =>
Effect.gen(function* () {
yield* Console.error(`[Platform] Error handling GET ${path}:`, cause);
return HttpServerResponse.text(`Internal Server Error`, {
status: 500,
});
}),
),
);
httpRouter = httpRouter.pipe(
HttpRouter.get(
Expand Down Expand Up @@ -722,8 +733,7 @@ export const makeClientLayer = <
// Static host served HTML but we couldn't find the data blob.
// Not fatal — some routes may legitimately have no loader data
// — but log it so a broken build/deploy doesn't sit invisible.
// eslint-disable-next-line no-console
console.warn(
yield* Console.warn(
`[@effex/platform] Fetched HTML for ${path} but couldn't find window.__EFFEX_DATA__. ` +
`Continuing with data: undefined.`,
);
Expand All @@ -736,17 +746,15 @@ export const makeClientLayer = <
} as unknown as RouteDataService;
}).pipe(
// Log before Effect.orDie so a failed fetch/parse doesn't become
// an invisible blank Outlet. Devs see the cause in the console;
// error trackers (Sentry, etc.) still catch it via console.error.
// an invisible blank Outlet. Effect's Console goes through a
// service (swappable via Layer for tests); default sink is
// browser console, so error trackers still see it.
Effect.tapError((err) =>
Effect.sync(() => {
// eslint-disable-next-line no-console
console.error(
`[@effex/platform] Failed to load route data for ${substituteParams(route.path, params)}. ` +
`Outlet will render empty.`,
err,
);
}),
Console.error(
`[@effex/platform] Failed to load route data for ${substituteParams(route.path, params)}. ` +
`Outlet will render empty.`,
err,
),
),
Effect.orDie,
),
Expand Down Expand Up @@ -987,7 +995,7 @@ export const buildStaticSite = (
{ concurrency: 10 },
);

console.log(`[SSG] Built ${rendered.length} pages to ${outDir}`);
yield* Console.log(`[SSG] Built ${rendered.length} pages to ${outDir}`);
});

// Run the program with user-provided layers
Expand Down
Loading