Skip to content

[Bug?]: Unable to use ErrorBoundary when throwing Error from cached function in combination with load #399

@bondehagen

Description

@bondehagen

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 😯

Node process exits with unhandled exception

Expected behavior 🤔

Load function should ignore errors and ErrorBoundary should get triggered.

Steps to reproduce 🕹

Steps:

import { Show, ErrorBoundary } from "solid-js";
import { type RouteDefinition, type RouteSectionProps, cache, createAsync } from "@solidjs/router";
import { HttpStatusCode } from "@solidjs/start";

export const route = {
  load: ({ params }) => getHouse(params.house)
} satisfies RouteDefinition;

const getHouse = cache(async (house: string) => {
  "use server"
  if (house != "gryffindor") {
    throw new Error("House not found");
  }
  return house;
}, "house");

export default function House(props: RouteSectionProps) {
  const house = createAsync(() => getHouse(props.params.house), {
    deferStream: true,
  });
  return (
    <ErrorBoundary
      fallback={(e) => (
        <Show when={e.message === "House not found"}>
          <HttpStatusCode code={404} />
          <h1>House not found</h1>
        </Show>
      )}
    >
      <div>{house()}</div>
    </ErrorBoundary>
  );
}
  1. Run http://localhost:3000/house/gryffindor and make sure that page works
  2. Run http://localhost:3000/house/notgryffindor and see that node process fail with unhandlet exception

Context 🔦

It should be possible to handle errors in combination with preloading data.

Your environment 🌎

System:
 OS: Windows

Node: v21.1.0

Packages:
 vinxi: 0.3.11
 solid-js: 1.8.16
 @solidjs/router: 0.13.1
 @solidjs/start: 1.0.0-rc.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions