Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug?]: Rejected promises in server fns are not handled correctly #1323

Closed
2 tasks done
marvin-j97 opened this issue Feb 10, 2024 · 6 comments · Fixed by #1325
Closed
2 tasks done

[Bug?]: Rejected promises in server fns are not handled correctly #1323

marvin-j97 opened this issue Feb 10, 2024 · 6 comments · Fixed by #1325
Labels
bug Something isn't working

Comments

@marvin-j97
Copy link
Contributor

marvin-j97 commented Feb 10, 2024

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 😯

This is similar but not the same as #1222
Here's a simple reproduction:

import { cache, createAsync } from "@solidjs/router";

const myFn = cache(async () => {
  "use server";

  await Promise.reject("oh no");

  return "Halló";
}, "myFn");

export default function Home() {
  const msg = createAsync(() => myFn(), {
    deferStream: true
  });

  return (
    <main>
      <h1>{msg()} world!</h1>
    </main>
  );
}

On initial SSR, Dev server crashes with Error: oh no, but should probably show an error page, and log something in the console, but not die.

When using client-side routing (going from /about to /broken page), an error is printed:

Uncaught (in promise) SyntaxError: Unexpected identifier 'no'
    at eval (<anonymous>)
    at deserialize (index.mjs?v=7b36de8d:3200:19)
    at SerovalChunkReader.next (server-runtime.ts?v=7b36de8d:43:14)
    at SerovalChunkReader.next (server-runtime.ts?v=7b36de8d:30:25)
    at async deserializeStream (server-runtime.ts?v=7b36de8d:60:18)

Seemingly, rejections are not taken into account correctly. Again, a pop-up telling the user a fatal error in the server function occured would be great.

Steps to reproduce 🕹

See example

Context 🔦

Obvious

Your environment 🌎

  • Using latest basic solid-cli example as of today
  • Chrome
  • Ubuntu
@marvin-j97 marvin-j97 added the bug Something isn't working label Feb 10, 2024
@marvin-j97 marvin-j97 changed the title D[Bug?]: Rejected promises in server fns are not handled correctly [Bug?]: Rejected promises in server fns are not handled correctly Feb 10, 2024
@lxsmnsyc
Copy link
Member

lxsmnsyc commented Feb 11, 2024

probably has something to do with cache 🤔

does it work normally without it?

@marvin-j97
Copy link
Contributor Author

probably has something to do with cache 🤔

does it work normally without it?

No.

CSR routing:

Error: Unknown error
    at castError (chunk-VFKAEII7.js?v=c4b37483:979:10)
    at chunk-VFKAEII7.js?v=c4b37483:364:79

SSR, crashes:

Error: oh no

@lxsmnsyc
Copy link
Member

Okay thanks! for the _server, can you show me what does the response look like?

@marvin-j97
Copy link
Contributor Author

Okay thanks! for the _server, can you show me what does the response look like?

oh no

(literally)

@marvin-j97
Copy link
Contributor Author

@lxsmnsyc Without using cache:

{
  "statusCode": 500,
  "stack": []
}

@lxsmnsyc
Copy link
Member

Just realized that this is the cause of the issue

if (!result || typeof result === "string") return result || null;

it was not following the expected format for the deserializer. Will fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants