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

$page.error not typed as HttpError #5970

Closed
austins opened this issue Aug 17, 2022 · 4 comments
Closed

$page.error not typed as HttpError #5970

austins opened this issue Aug 17, 2022 · 4 comments

Comments

@austins
Copy link

austins commented Aug 17, 2022

Describe the bug

In SvelteKit 1.0.0-next.415, $page.error isn't typed as HttpError (which is not exported publicly).

Reproduction

If you try to output $page.error.message in +error.svelte you'll get an Unsafe member access .message on an any value. eslint(@typescript-eslint/no-unsafe-member-access) error.

<script lang="ts">
    import { page } from "$app/stores";
</script>

<h1>{$page.status}: {$page.error.message}</h1>

Logs

No response

System Info

System:
    OS: Windows 10 10.0.22000
    CPU: (24) x64 AMD Ryzen 9 3900X 12-Core Processor
    Memory: 2.33 GB / 15.93 GB
  Binaries:
    Node: 16.16.0 - ~\scoop\apps\nodejs-lts\current\node.EXE
    npm: 8.15.1 - ~\scoop\apps\nodejs-lts\current\bin\npm.CMD
  Browsers:
    Edge: Spartan (44.22000.120.0), Chromium (104.0.1293.47)
    Internet Explorer: 11.0.22000.120
  npmPackages:
    @sveltejs/adapter-node: ^1.0.0-next.86 => 1.0.0-next.86
    @sveltejs/kit: ^1.0.0-next.415 => 1.0.0-next.415
    @sveltejs/vite-plugin-svelte: ^1.0.1 => 1.0.1
    svelte: ^3.49.0 => 3.49.0
    vite: ^3.0.8 => 3.0.8

Severity

annoyance

Additional Information

No response

@dummdidumm
Copy link
Member

This is correct, because this can be something else than HttpError, too (an Error for example, though that one has message, too). Not sure if we can do something here to appease the common case where message exists.

@austins
Copy link
Author

austins commented Aug 17, 2022

For now, we can cast the type like so:

    $: error = $page.error as Error;

@benmccann benmccann added this to the 1.0 milestone Aug 17, 2022
@Rich-Harris
Copy link
Member

Since errors have to be converted to POJOs to cross the serialization boundary between server and client, their type is really something like

{ status: number, message: string } |
{ name: string, message: string, [key: string]: any }

I feel like we could probably make this work?

@Rich-Harris Rich-Harris modified the milestones: 1.0, whenever Aug 27, 2022
@dummdidumm
Copy link
Member

Closed via #6586

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants