API reference / @evolu/common / Result / Err
Interface: Err<E>
Defined in: packages/common/src/Result.ts:397
An error Result.
The error property can be any type that describes the error. For normal
domain logic, use a plain object. This allows us to structure errors with
custom fields (e.g., { type: "MyError", code: 123 }). Messages for users
belong to translations, not to error objects.
If you need a stack trace for debugging, use an Error instance or a custom
error class to include additional metadata.
Examples
Domain logic error (plain object, recommended)
const failure = err({
type: "ParseJsonError",
code: 1001,
input: "foo",
});
Debugging with stack trace (error instance)
const failure = err(new Error("Something went wrong"));
Custom error class
class MyCustomError extends Error {
constructor(
public code: number,
public input: string,
) {
super(`Error ${code} on input: ${input}`);
this.name = "MyCustomError";
}
}
const failure = err(new MyCustomError(404, "bad-input"));
Type Parameters
| Type Parameter |
|---|
E |
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
error | readonly | E | packages/common/src/Result.ts:399 |
ok | readonly | false | packages/common/src/Result.ts:398 |