| 1 | package suite |
| 2 | |
| 3 | import ( |
| 4 | "errors" |
| 5 | "fmt" |
| 6 | ) |
| 7 | |
| 8 | // ErrNotAvailable is the whole vocabulary of an S3 refusal. |
| 9 | // |
| 10 | // Doctrine §4.2: a content fetch for anything outside custody answers 404, |
| 11 | // never 403, identical to "does not exist". Since revision 10 (Paul, |
| 12 | // 2026-11-01) custody is every live item, so the refusal covers a deleted |
| 13 | // item, an unknown id and a revision that is not current — one answer, so a |
| 14 | // consumer cannot tell a deletion from an id it made up. |
| 15 | var ErrNotAvailable = errors.New("suite: item not available") |
| 16 | |
| 17 | // ErrContractBreach marks a sibling answering in a way the contract forbids. |
| 18 | // It is separate from a refusal and from an outage because it is neither: it |
| 19 | // is a bug in the sibling that a consumer should surface rather than absorb. |
| 20 | var ErrContractBreach = errors.New("suite: sibling broke the contract") |
| 21 | |
| 22 | // DecodeS3 reads a content fetch. There is no asker anywhere in this call: |
| 23 | // S3 is custody-scoped and person-less, and memoria's draft 3 added a person |
| 24 | // to it, which both broke the ingest path — the warm-up, the rebuild and |
| 25 | // derived-artefact regeneration have no asker — and (before revision 10, |
| 26 | // when a store could hold only team-visible items) pulled individually |
| 27 | // granted rows into a store that might not hold them. Since revision 10 a |
| 28 | // consumer holds every live item and who sees one is S2's question. |
| 29 | func DecodeS3(status int, body []byte) ([]byte, error) { |
| 30 | switch { |
| 31 | case status >= 200 && status <= 299: |
| 32 | return body, nil |
| 33 | |
| 34 | case status == 404: |
| 35 | return nil, ErrNotAvailable |
| 36 | |
| 37 | case status == 403: |
| 38 | // "404, never 403" is the rule, because 403 means "this exists and |
| 39 | // you may not have it" — the one fact custody hides. A sibling |
| 40 | // answering 403 is leaking, and folding it into ErrNotAvailable would |
| 41 | // keep that leak invisible to everyone downstream. |
| 42 | return nil, fmt.Errorf("%w: S3 answered 403 where the contract requires 404", ErrContractBreach) |
| 43 | |
| 44 | default: |
| 45 | return nil, fmt.Errorf("suite: S3 answered %d", status) |
| 46 | } |
| 47 | } |
| 48 | |