(error: object): ReadonlyRecord<string, unknown>Reads the ErrorReporter.attributes annotation from an error object,
returning an empty record when unset.
When to use
Use to inspect the attributes that reporter callbacks will receive for an object error.
Details
Returns the value stored under ErrorReporter.attributes, or the module's
shared empty record when the annotation is absent.
Gotchas
The annotation value is returned as-is; this helper does not validate or clone it.
export const const getAttributes: (
error: object
) => ReadonlyRecord<string, unknown>
Reads the ErrorReporter.attributes annotation from an error object,
returning an empty record when unset.
When to use
Use to inspect the attributes that reporter callbacks will receive for an
object error.
Details
Returns the value stored under ErrorReporter.attributes, or the module's
shared empty record when the annotation is absent.
Gotchas
The annotation value is returned as-is; this helper does not validate or
clone it.
getAttributes = (error: objecterror: object): type ReadonlyRecord<in out K extends string | symbol, out A> = { readonly [P in K]: A; }Represents a readonly record with keys of type K and values of type A.
This is the foundational type for immutable key-value mappings in Effect.
Example (Defining a readonly record type)
import type { Record } from "effect"
// Creating a readonly record type
type UserRecord = Record.ReadonlyRecord<"name" | "age", string | number>
const user: UserRecord = {
name: "John",
age: 30
}
Namespace containing utility types for working with readonly records.
These types help with type-level operations on record keys and values.
Example (Using readonly record helper types)
import type { Record } from "effect"
// Using NonLiteralKey to convert literal keys to generic types
type GenericKey = Record.ReadonlyRecord.NonLiteralKey<"foo" | "bar"> // string
// Using IntersectKeys to find common keys between record types
type CommonKeys = Record.ReadonlyRecord.IntersectKeys<"a" | "b", "b" | "c"> // "b"
ReadonlyRecord<string, unknown> => {
return const attributes: attributesDefines the string property key used to attach extra key/value metadata to an object
error report.
When to use
Use to type the property key that attaches metadata to object error reports.
Details
Reporters receive these attributes alongside the error, making it easy to
include contextual information such as user IDs, request IDs, or other
domain-specific debugging data.
Defines the runtime property key used to attach extra key/value metadata to an object
error report.
When to use
Use to attach domain metadata to object errors so reporter callbacks receive
it with the reported failure.
Details
Set error[ErrorReporter.attributes] to a record of metadata that should be
forwarded to reporters alongside the error.
Example (Setting error attributes)
import { Data, ErrorReporter } from "effect"
class PaymentError extends Data.TaggedError("PaymentError")<{
readonly orderId: string
}> {
readonly [ErrorReporter.attributes] = {
orderId: this.orderId
}
}
attributes in error: objecterror ? error: object &
Record<
"~effect/ErrorReporter/attributes",
unknown
>
error[const attributes: attributesDefines the string property key used to attach extra key/value metadata to an object
error report.
When to use
Use to type the property key that attaches metadata to object error reports.
Details
Reporters receive these attributes alongside the error, making it easy to
include contextual information such as user IDs, request IDs, or other
domain-specific debugging data.
Defines the runtime property key used to attach extra key/value metadata to an object
error report.
When to use
Use to attach domain metadata to object errors so reporter callbacks receive
it with the reported failure.
Details
Set error[ErrorReporter.attributes] to a record of metadata that should be
forwarded to reporters alongside the error.
Example (Setting error attributes)
import { Data, ErrorReporter } from "effect"
class PaymentError extends Data.TaggedError("PaymentError")<{
readonly orderId: string
}> {
readonly [ErrorReporter.attributes] = {
orderId: this.orderId
}
}
attributes] as any : const emptyAttributes: ReadonlyRecord<
string,
unknown
>
emptyAttributes
}