{"modulePath":"github.com/uber/submitqueue","version":"v0.3.0-20261125210437-add1a4bd2ea2","isLatest":false,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package failure\n\nPackage failure holds the shared description of why processing failed: a human-readable message, the entities the failure is about, and free-form detail. It is the vocabulary a producer of a failure and a consumer of it share when they are separated by a queue, so the consumer reads fields rather than parsing prose.\n\nThe package is deliberately domain-agnostic. It says a failure has subjects and what shape a subject is; which subject types exist is a domain's own business.\n\n## Functions\n\n```go\nfunc Encode(f Failure) ([]byte, error)\n```\nEncode returns the JSON encoding of the structured half of f — its subjects and detail — or nil when there is no structure to store.\n\nMessage is deliberately excluded. It travels as plain text alongside this blob so that it stays legible to anything reading the underlying store directly, and so decoding never has to guess whether a stored string is an encoded failure or a message that merely looks like one.\n\n## Types\n\n```go\ntype Failure struct {\n\t// Message is the human-readable reason, typically an error's text. It is\n\t// the one field always present, and the one a person reads first.\n\tMessage string `json:\"-\"`\n\t// Subjects are the entities this failure is about, in no significant\n\t// order. Empty means unattributed — see the type comment.\n\tSubjects []Subject `json:\"subjects,omitempty\"`\n\t// Detail is free-form structured context: whatever the producer knows that\n\t// does not fit the message. Values survive a JSON round trip, so numbers\n\t// come back as float64 regardless of what went in.\n\tDetail map[string]any `json:\"detail,omitempty\"`\n}\n```\nFailure describes why processing failed.\n\nA failure is always about something. When no single record is at fault, the subject is the wider thing that is — the queue, the tenant, the job — rather than an empty list. That keeps absence from carrying meaning: no subjects at all means the failure is \\*unattributed\\*, which is a genuine third state (nothing recorded one, or the record predates attribution) and not a claim that nothing was to blame.\n\n```go\nfunc Decode(data []byte) (Failure, error)\n```\nDecode parses the structured half produced by Encode. Empty input yields the zero Failure, which is how an unattributed failure reads.\n\nThe returned Message is always empty: the caller holds it separately and fills it in.\n\n```go\nfunc New(message string, subjects ...Subject) Failure\n```\nNew builds a Failure with a message and the subjects it is about.\n\n```go\nfunc (f Failure) IDsOfType(subjectType string) []string\n```\nIDsOfType returns the IDs of every subject with the given type, in the order they appear. The result is empty when the failure names no such subject, which is how a consumer asks \"is this about one of mine?\" without inspecting the slice itself.\n\n```go\ntype Subject struct {\n\t// Type labels what kind of entity ID names, e.g. \"batch\" or \"queue\".\n\t// Values are chosen by the domain that raises the failure; this package\n\t// neither defines nor validates them. Empty means the type is unknown.\n\tType string `json:\"type\"`\n\t// ID identifies the entity within its type. Opaque here: no format is\n\t// assumed and none is parsed.\n\tID string `json:\"id\"`\n}\n```\nSubject names one entity a failure is about.\n\nIts purpose is attribution: a consumer reconciling a failure has to know what to act on, and the entity named on the message that failed is not always the entity at fault — a job that reads many records can fail because of any of them, or because of none of them individually.\n\n","path":"github.com/uber/submitqueue/platform/base/failure","name":"failure","synopsis":"Package failure holds the shared description of why processing failed: a human-readable message, the entities the failure is about, and free-form detail.","isRedistributable":true}
