Skip to content

Export ActionFailure to allow instanceof #12611

@probablykasper

Description

@probablykasper

Describe the problem

I have some shared logic for parsing user input, but it's not that convenient to deal with success/error types.

Describe the proposed solution

ActionFailure is a class, but SvelteKit exposes it as an interface. It would be nice to simply return fail() and do instanceof ActionFailure:

function parse(value: T | null) {
	if (!value) {
		return fail(400, { message: 'Too high' })
	}
	// ...
	return value
}

// Action:
const result = parse('test')
if (result instanceof ActionFailure) {
	return result
}

Alternatives considered

  • Creating my own class
  • Returning a result type like { value: T, error: null } | { value: null, error: string }
  • Use the Error class message as an intermediate, if I only need an error string

Importance

nice to have

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions