API Reference / @evolu/common / Result / Err
Interface: Err<E>
Defined in: packages/common/src/Result.ts:297
An error Result.
The error
property can be any type that describes the error. For normal
business 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 stacktrace for debugging, use an Error
instance or a custom
error class to include additional metadata.
Examples
Business 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:299 |
ok | readonly | false | packages/common/src/Result.ts:298 |