Skip to content

If a function wrapped in action throws some error it should be possible to catch it. #387

@elite174

Description

@elite174

Describe the bug

Let's consider this example:

const myAction = action(() => throw new Error("Some error"));

// somewhere in a component
const doMyAction = useAction(myAction);

doMyAction().then(() => {
   // this function will always be executed despite the fact that the action failed.
   console.log('Action resolves without any error');
}, (error) => {
   // this function will never catch an error
   console.error('An error occured');
});

This error relates to this line: https://github.com/solidjs/solid-router/blob/main/src/data/action.ts#L97
Perhaps, handler should check the argument type (to preserve the current possibility to throw redirect or revalidate) and throw an error if the argument is not solid-related thing.

Your Example Website or App

see description

Steps to Reproduce the Bug or Issue

run this code

const myAction = action(() => throw new Error("Some error"));

// somewhere in a component
const doMyAction = useAction(myAction);

doMyAction().then(() => {
   // this function will always be executed despite the fact that the action failed.
   console.log('Action resolves without any error');
}, (error) => {
   // this function will never catch an error
   console.error('An error occured');
});```

### Expected behavior

Error handler should handle errors.

### Screenshots or Videos

_No response_

### Platform

any

### Additional context

_No response_

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions