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

Add info about error casting in in createResource #1086

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

amirhhashemi
Copy link
Collaborator

  • I have read the Contribution guide
  • This PR references an issue (except for typos, broken links, or other minor problems)

Description(required)

This PR adds more information about how createResource casts errors.

Related issues & labels

Copy link

stackblitz bot commented Feb 16, 2025

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link

netlify bot commented Feb 16, 2025

Deploy Preview for solid-docs ready!

Name Link
🔨 Latest commit eb1213e
🔍 Latest deploy log https://app.netlify.com/sites/solid-docs/deploys/67b1ed66be20f100080b93c8
😎 Deploy Preview https://deploy-preview-1086--solid-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Comment on lines +37 to +41
<Callout title="Note">

If you anticipate errors, you may want to wrap `createResource` in an [ErrorBoundary](/reference/components/error-boundary).

</Callout>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is out of place but I couldn't find a better place for it. It shouldn't be here in the first place. Maybe we should mention it somewhere here instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree - probably best to add under Using createResource

Copy link

netlify bot commented Feb 16, 2025

Deploy Preview for solid-docs ready!

Name Link
🔨 Latest commit ef3336a
🔍 Latest deploy log https://app.netlify.com/sites/solid-docs/deploys/67b508715e1b3200086ac4f5
😎 Deploy Preview https://deploy-preview-1086--solid-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.


As of **v1.4.0**, `data.latest` will return the last returned value and won't trigger [Suspense](/reference/components/suspense) and [transitions](#TODO); if no value has been returned yet, `data.latest` acts the same as `data()`.
This can be useful if you want to show the out-of-date data while the new data is loading.
- `data.loading` tells you if the fetcher has been called but not returned.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `data.loading` tells you if the fetcher has been called but not returned.
- `data.loading`: whether the fetcher has been called but not returned.

As of **v1.4.0**, `data.latest` will return the last returned value and won't trigger [Suspense](/reference/components/suspense) and [transitions](#TODO); if no value has been returned yet, `data.latest` acts the same as `data()`.
This can be useful if you want to show the out-of-date data while the new data is loading.
- `data.loading` tells you if the fetcher has been called but not returned.
- `data.error` tells you if the request has errored out.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `data.error` tells you if the request has errored out.
- `data.error`: if the request has errored out.

This can be useful if you want to show the out-of-date data while the new data is loading.
- `data.loading` tells you if the fetcher has been called but not returned.
- `data.error` tells you if the request has errored out.
`createResource` always provides an `Error` object for `data.error`, even if the fetcher throws something else.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`createResource` always provides an `Error` object for `data.error`, even if the fetcher throws something else.
`createResource`: provides an `Error` object for `data.error`. It will show even if the fetcher throws something else.

Comment on lines +33 to +35
- If the fetcher throws an `Error` instance, `data.error` will be that instance.
- If the fetcher throws a string, `data.error.message` will contain that string.
- If the fetcher throws a value that is neither an `Error` nor a string, that value will be available as `data.error.cause`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- If the fetcher throws an `Error` instance, `data.error` will be that instance.
- If the fetcher throws a string, `data.error.message` will contain that string.
- If the fetcher throws a value that is neither an `Error` nor a string, that value will be available as `data.error.cause`.
- Fetcher throws an `Error` instance, `data.error` will be that instance.
- If the fetcher throws a string, `data.error.message` will contain that string.
- When the fetcher throws a value that is neither an `Error` nor a string, that value will be available as `data.error.cause`.

Comment on lines +37 to +41
<Callout title="Note">

If you anticipate errors, you may want to wrap `createResource` in an [ErrorBoundary](/reference/components/error-boundary).

</Callout>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree - probably best to add under Using createResource


</Callout>

- As of **v1.4.0**, `data.latest` will return the last returned value and won't trigger [Suspense](/reference/components/suspense) and [transitions](#TODO); if no value has been returned yet, `data.latest` acts the same as `data()`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- As of **v1.4.0**, `data.latest` will return the last returned value and won't trigger [Suspense](/reference/components/suspense) and [transitions](#TODO); if no value has been returned yet, `data.latest` acts the same as `data()`.
- As of **v1.4.0**, `data.latest` returns the last value received and will not trigger [Suspense](/reference/components/suspense) or [transitions](#TODO); if no value has been returned yet, `data.latest` will act the same as `data()`.

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

Successfully merging this pull request may close these issues.

The castError behavior of createResource should be documented
2 participants