@softistx/s3 0.0.0-stage → 0.13.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +609 -2
  3. package/dist/bucket/bind-bucket.d.ts +42 -0
  4. package/dist/bucket/bind-bucket.d.ts.map +1 -0
  5. package/dist/bucket/bound-bucket.d.ts +119 -0
  6. package/dist/bucket/bound-bucket.d.ts.map +1 -0
  7. package/dist/bucket/context.d.ts +55 -0
  8. package/dist/bucket/context.d.ts.map +1 -0
  9. package/dist/bucket/define-bucket.d.ts +16 -0
  10. package/dist/bucket/define-bucket.d.ts.map +1 -0
  11. package/dist/bucket/disposition.d.ts +9 -0
  12. package/dist/bucket/disposition.d.ts.map +1 -0
  13. package/dist/bucket/guards.d.ts +38 -0
  14. package/dist/bucket/guards.d.ts.map +1 -0
  15. package/dist/bucket/operations/counted-stream.d.ts +26 -0
  16. package/dist/bucket/operations/counted-stream.d.ts.map +1 -0
  17. package/dist/bucket/operations/deadline.d.ts +21 -0
  18. package/dist/bucket/operations/deadline.d.ts.map +1 -0
  19. package/dist/bucket/operations/fetch-object.d.ts +68 -0
  20. package/dist/bucket/operations/fetch-object.d.ts.map +1 -0
  21. package/dist/bucket/operations/list-xml.d.ts +18 -0
  22. package/dist/bucket/operations/list-xml.d.ts.map +1 -0
  23. package/dist/bucket/operations/list.d.ts +12 -0
  24. package/dist/bucket/operations/list.d.ts.map +1 -0
  25. package/dist/bucket/operations/open-answer.d.ts +5 -0
  26. package/dist/bucket/operations/open-answer.d.ts.map +1 -0
  27. package/dist/bucket/operations/open-range.d.ts +10 -0
  28. package/dist/bucket/operations/open-range.d.ts.map +1 -0
  29. package/dist/bucket/operations/open-relay.d.ts +8 -0
  30. package/dist/bucket/operations/open-relay.d.ts.map +1 -0
  31. package/dist/bucket/operations/open.d.ts +4 -0
  32. package/dist/bucket/operations/open.d.ts.map +1 -0
  33. package/dist/bucket/operations/post-policy.d.ts +77 -0
  34. package/dist/bucket/operations/post-policy.d.ts.map +1 -0
  35. package/dist/bucket/operations/post-signer.d.ts +21 -0
  36. package/dist/bucket/operations/post-signer.d.ts.map +1 -0
  37. package/dist/bucket/operations/presign-post.d.ts +44 -0
  38. package/dist/bucket/operations/presign-post.d.ts.map +1 -0
  39. package/dist/bucket/operations/presign.d.ts +34 -0
  40. package/dist/bucket/operations/presign.d.ts.map +1 -0
  41. package/dist/bucket/operations/put-body.d.ts +13 -0
  42. package/dist/bucket/operations/put-body.d.ts.map +1 -0
  43. package/dist/bucket/operations/query-sign.d.ts +15 -0
  44. package/dist/bucket/operations/query-sign.d.ts.map +1 -0
  45. package/dist/bucket/operations/reads.d.ts +8 -0
  46. package/dist/bucket/operations/reads.d.ts.map +1 -0
  47. package/dist/bucket/operations/sized-body.d.ts +24 -0
  48. package/dist/bucket/operations/sized-body.d.ts.map +1 -0
  49. package/dist/bucket/operations/slice.d.ts +4 -0
  50. package/dist/bucket/operations/slice.d.ts.map +1 -0
  51. package/dist/bucket/operations/writes.d.ts +10 -0
  52. package/dist/bucket/operations/writes.d.ts.map +1 -0
  53. package/dist/bucket/shape.d.ts +6 -0
  54. package/dist/bucket/shape.d.ts.map +1 -0
  55. package/dist/bucket/types.d.ts +164 -0
  56. package/dist/bucket/types.d.ts.map +1 -0
  57. package/dist/chunks/index-jgjey570.js +118 -0
  58. package/dist/chunks/index-jgjey570.js.map +13 -0
  59. package/dist/errors/is-bucket-unavailable.d.ts +18 -0
  60. package/dist/errors/is-bucket-unavailable.d.ts.map +1 -0
  61. package/dist/errors/s3-error.d.ts +80 -0
  62. package/dist/errors/s3-error.d.ts.map +1 -0
  63. package/dist/index.d.ts +8 -0
  64. package/dist/index.d.ts.map +1 -0
  65. package/dist/index.js +1288 -0
  66. package/dist/index.js.map +32 -0
  67. package/dist/testing/fetch-archive.d.ts +8 -0
  68. package/dist/testing/fetch-archive.d.ts.map +1 -0
  69. package/dist/testing/index.d.ts +6 -0
  70. package/dist/testing/index.d.ts.map +1 -0
  71. package/dist/testing/index.js +416 -0
  72. package/dist/testing/index.js.map +16 -0
  73. package/dist/testing/ports.d.ts +15 -0
  74. package/dist/testing/ports.d.ts.map +1 -0
  75. package/dist/testing/ready.d.ts +49 -0
  76. package/dist/testing/ready.d.ts.map +1 -0
  77. package/dist/testing/reaper.d.ts +4 -0
  78. package/dist/testing/reaper.d.ts.map +1 -0
  79. package/dist/testing/seaweedfs.d.ts +64 -0
  80. package/dist/testing/seaweedfs.d.ts.map +1 -0
  81. package/dist/testing/test-s3.d.ts +35 -0
  82. package/dist/testing/test-s3.d.ts.map +1 -0
  83. package/dist/testing/weed.d.ts +17 -0
  84. package/dist/testing/weed.d.ts.map +1 -0
  85. package/docs/README.md +17 -0
  86. package/docs/guide/buckets.md +220 -0
  87. package/docs/guide/presigned-urls.md +403 -0
  88. package/docs/guide/reads.md +417 -0
  89. package/docs/guide/testing.md +151 -0
  90. package/docs/guide/writes.md +374 -0
  91. package/docs/roadmap.md +116 -0
  92. package/docs/troubleshooting.md +982 -0
  93. package/package.json +61 -5
@@ -0,0 +1,982 @@
1
+ # Troubleshooting
2
+
3
+ This package's error class for refusals is `S3Error`, with a `code` of
4
+ `WRONG_TYPE`, `TOO_LARGE`, `UNMEASURABLE`, `WRONG_OPTION`, `SIZE_MISMATCH`,
5
+ `SOURCE_FAILED`, `RANGE_NOT_SATISFIABLE` or `TIMEOUT`, and the object `key` it
6
+ was about — never the body. Every one of them but `TIMEOUT`, `SIZE_MISMATCH`,
7
+ `SOURCE_FAILED` and `RANGE_NOT_SATISFIABLE` is raised **before** anything is
8
+ sent, so a refused write stored nothing; `TIMEOUT` is raised after, when a
9
+ deadline passes, `SIZE_MISMATCH` after, when a streamed body is not the length
10
+ it declared, `SOURCE_FAILED` after, when its source threw or gave something
11
+ that is not bytes (nothing is stored then either), and
12
+ `RANGE_NOT_SATISFIABLE` after the service's answer to a ranged `open`, a read
13
+ that changed nothing. It throws two other
14
+ kinds, for what is not the caller's input: a `TypeError` from `defineBucket`
15
+ for a definition that could never work, and from `presignPost` — or a `list`
16
+ under a deadline — when its secret is not the one Bun signs with (changed or
17
+ deleted since the process started), and from the bound `parseKey` when the
18
+ definition has none; and a plain `Error` from `presignPost`, or
19
+ a `list` under a deadline, when the URL Bun signed cannot be read. Each has
20
+ its entry below. The service's own failures are not this package's `S3Error`:
21
+ they come back as Bun raises them (an `Error` that Bun also names `S3Error`,
22
+ with S3's `code`); the entries below say which is which.
23
+ A wrong `acl` is this package's own refusal on a `put` **and** on the
24
+ presigned calls, so one class and one code cover them all. A message reports what was
25
+ wrong by its **shape** — `another string`, `a fraction`, `the type given` —
26
+ and never quotes the value, which can come off a request body. Every
27
+ refusal also names the call and the bucket it was on, so a log line says which
28
+ of an application's buckets and calls produced it, in one of two forms: the
29
+ refusals shared with `put` and the other presigned calls **end** with it —
30
+ `(put on "avatars")`, `(presignGet on "avatars")`, `(presignPut on …)`,
31
+ `(presignPost on …)` — while `presignPost`'s own refusals, and its two
32
+ `TypeError`s and its plain `Error`, **lead** with it:
33
+ `presignPost on "avatars": …`. Bun names its own *service*
34
+ failures `S3Error` as well, so it is `instanceof S3Error` against the class
35
+ this package exports that tells those apart — never `error.name`. (Bun's
36
+ refusal of a wrong argument is a different thing again: a plain `TypeError`,
37
+ named `"TypeError"`.) The Bun messages were measured on Bun 1.4.2.
38
+
39
+ - **Install and import**
40
+ - [`Cannot find package 'bun'`](#cannot-find-package-bun)
41
+ - [`Cannot find module 'bun' or its corresponding type declarations.`](#cannot-find-module-bun-or-its-corresponding-type-declarations)
42
+ - **Configuration**
43
+ - [`defineBucket: a bucket definition needs a bucket`](#definebucket-a-bucket-definition-needs-a-bucket)
44
+ - [`defineBucket: "avatars" has a maxSize of 0; it is a number of bytes, and must be above zero`](#definebucket-avatars-has-a-maxsize-of-0-it-is-a-number-of-bytes-and-must-be-above-zero)
45
+ - [`defineBucket: "avatars" accepts an empty list of content types, so nothing could ever be written. …`](#definebucket-avatars-accepts-an-empty-list-of-content-types-so-nothing-could-ever-be-written-)
46
+ - **Writes refused before they are sent**
47
+ - [`"avatars" accepts image/png, image/jpeg, not the type given (put on "avatars")`](#avatars-accepts-imagepng-imagejpeg-not-the-type-given-put-on-avatars)
48
+ - [``"avatars" accepts image/png, image/jpeg, and no content type was named. Pass `type` (put on "avatars")``](#avatars-accepts-imagepng-imagejpeg-and-no-content-type-was-named-pass-type-put-on-avatars)
49
+ - [`"avatars" accepts 2097152 bytes at most, and this body is 5242880 (put on "avatars")`](#avatars-accepts-2097152-bytes-at-most-and-this-body-is-5242880-put-on-avatars)
50
+ - [`"avatars" has a maxSize, and this body's size cannot be known before sending it. …`](#avatars-has-a-maxsize-and-this-bodys-size-cannot-be-known-before-sending-it-)
51
+ - [`the stream ended after 100 bytes, short of the declared size of 150 bytes; the upload was aborted and nothing is stored (put on "avatars")`](#the-stream-ended-after-100-bytes-short-of-the-declared-size-of-150-bytes-the-upload-was-aborted-and-nothing-is-stored-put-on-avatars)
52
+ - [`the stream failed after 40 bytes; the upload was aborted and nothing is stored (put on "avatars")`](#the-stream-failed-after-40-bytes-the-upload-was-aborted-and-nothing-is-stored-put-on-avatars)
53
+ - [`size is a whole number of bytes, 0 or more; got a fraction (put on "avatars")`](#size-is-a-whole-number-of-bytes-0-or-more-got-a-fraction-put-on-avatars)
54
+ - [`storageClass must be one of STANDARD, DEEP_ARCHIVE, EXPRESS_ONEZONE, …; got another string (put on "avatars")`](#storageclass-must-be-one-of-standard-deep_archive-express_onezone--got-another-string-put-on-avatars)
55
+ - [`acl must be one of private, public-read, public-read-write, …; got another string (put on "avatars")`](#acl-must-be-one-of-private-public-read-public-read-write--got-another-string-put-on-avatars)
56
+ - [`contentDisposition must be a non-empty string of printable ASCII, with no line break or control character (spell a non-ASCII filename as filename*=UTF-8''...); got a string with other characters (presignGet on "avatars")`](#contentdisposition-must-be-a-non-empty-string-of-printable-ascii-with-no-line-break-or-control-character-spell-a-non-ascii-filename-as-filenameutf-8-got-a-string-with-other-characters-presignget-on-avatars)
57
+ - [`expiresIn is seconds, and must be above 0 and at most 604800 …; got a number above that (presignGet on "avatars")`](#expiresin-is-seconds-and-must-be-above-0-and-at-most-604800-seven-days-which-is-s3s-own-limit-got-a-number-above-that-presignget-on-avatars)
58
+ - **Presigned POSTs refused before they are signed**
59
+ - [``presignPost on "uploads": this bucket has no maxSize, … Pass `maxSize`, in bytes``](#presignpost-on-uploads-this-bucket-has-no-maxsize-and-a-presigned-post-is-a-bound-on-what-a-browser-uploads-pass-maxsize-in-bytes)
60
+ - [`presignPost on "avatars": maxSize cannot be above the bucket's own 2097152 bytes; got a larger number`](#presignpost-on-avatars-maxsize-cannot-be-above-the-buckets-own-2097152-bytes-got-a-larger-number)
61
+ - [`presignPost on "avatars": maxSize is a whole number of bytes, at least 1; got a string`](#presignpost-on-avatars-maxsize-is-a-whole-number-of-bytes-at-least-1-got-a-string)
62
+ - [`presignPost on "avatars": minSize is above maxSize, so no body could be posted`](#presignpost-on-avatars-minsize-is-above-maxsize-so-no-body-could-be-posted)
63
+ - [``presignPost on "avatars": this bucket accepts image/png, image/jpeg, and a prefix would let another type through. …``](#presignpost-on-avatars-this-bucket-accepts-imagepng-imagejpeg-and-a-prefix-would-let-another-type-through-pass-one-of-them-as-type-)
64
+ - [`presignPost on "uploads": type is a content type or { startsWith }; got a number`](#presignpost-on-uploads-type-is-a-content-type-or--startswith--got-a-number)
65
+ - [`"avatars" accepts image/png, image/jpeg, not the type given (presignPost on "avatars")`](#avatars-accepts-imagepng-imagejpeg-not-the-type-given-presignpost-on-avatars)
66
+ - [`presignPost on "avatars": the secret access key this package would sign with is not the one Bun signs with, so the service would refuse the form. …`](#presignpost-on-avatars-the-secret-access-key-this-package-would-sign-with-is-not-the-one-bun-signs-with-so-the-service-would-refuse-the-form-)
67
+ - [`presignPost on "avatars": no secret access key to sign with, while Bun has one. …`](#presignpost-on-avatars-no-secret-access-key-to-sign-with-while-bun-has-one-)
68
+ - [`presignPost on "avatars": the URL Bun signed has no credential scope, …`](#presignpost-on-avatars-the-url-bun-signed-has-no-credential-scope-or-not-the-key-at-the-end-of-its-path-so-there-is-nowhere-to-post-the-form-)
69
+ - **Testing**
70
+ - [`WEED_BIN is /nowhere/weed, which does not exist`](#weed_bin-is-nowhereweed-which-does-not-exist)
71
+ - [`binary is /nowhere/weed, which does not exist`](#binary-is-nowhereweed-which-does-not-exist)
72
+ - [`No SeaweedFS binary for win32/x64: install one and set WEED_BIN to its path.`](#no-seaweedfs-binary-for-win32x64-install-one-and-set-weed_bin-to-its-path)
73
+ - [`SeaweedFS 4.47 linux_amd64.tar.gz has SHA-256 …, expected …: refusing to run it.`](#seaweedfs-447-linux_amd64targz-has-sha-256--expected--refusing-to-run-it)
74
+ - [`No pinned SHA-256 for SeaweedFS 4.47 plan9_amd64.tar.gz: refusing to run an unchecked download.`](#no-pinned-sha-256-for-seaweedfs-447-plan9_amd64targz-refusing-to-run-an-unchecked-download)
75
+ - [`GET https://github.com/seaweedfs/seaweedfs/releases/download/4.47/linux_amd64.tar.gz answered 404`](#get-httpsgithubcomseaweedfsseaweedfsreleasesdownload447linux_amd64targz-answered-404)
76
+ - [`SeaweedFS did not serve S3 on http://127.0.0.1:24561 in 90s (bucket "avatars"). Its log, …/weed.log, says:`](#seaweedfs-did-not-serve-s3-on-http12700124561-in-90s-bucket-avatars-its-log-weedlog-says)
77
+ - [`reset (list) on "avatars": the test S3 server gave no answer in 3000ms; it is stuck`](#reset-list-on-avatars-the-test-s3-server-gave-no-answer-in-3000ms-it-is-stuck)
78
+ - [`createBucket: "x" is not a bucket name S3 accepts: 3 to 63 characters, lowercase letters, digits, dots and hyphens, starting and ending with a letter or digit`](#createbucket-x-is-not-a-bucket-name-s3-accepts-3-to-63-characters-lowercase-letters-digits-dots-and-hyphens-starting-and-ending-with-a-letter-or-digit)
79
+ - [`no free block of 8 consecutive ports`](#no-free-block-of-8-consecutive-ports)
80
+ - **Deadlines**
81
+ - [`timeoutMs is a whole number of milliseconds, 1 or more; got a fraction (stat on "avatars")`](#timeoutms-is-a-whole-number-of-milliseconds-1-or-more-got-a-fraction-stat-on-avatars)
82
+ - [`bindBucket on "avatars": publicEndpoint is an absolute URL such as https://media.example.com; got a string`](#bindbucket-on-avatars-publicendpoint-is-an-absolute-url-such-as-httpsmediaexamplecom-got-a-string)
83
+ - [`bindBucket on "avatars": publicEndpoint is an absolute URL such as https://media.example.com; got an empty string`](#bindbucket-on-avatars-publicendpoint-is-an-absolute-url-such-as-httpsmediaexamplecom-got-an-empty-string)
84
+ - [`stat on "avatars": no answer in 5000ms`](#stat-on-avatars-no-answer-in-5000ms)
85
+ - [`put on "avatars": nothing moved in 300ms`](#put-on-avatars-nothing-moved-in-300ms)
86
+ - **Reads with `open`**
87
+ - [`range is { start, end? } with 0 <= start < end, or { suffix } with suffix >= 1, as whole numbers; … (open on "media")`](#range-is--start-end-with-0--start--end-or--suffix--with-suffix--1-as-whole-numbers--open-on-media)
88
+ - [`open on "media": the range starts at or past the end of the object (100 bytes)`](#open-on-media-the-range-starts-at-or-past-the-end-of-the-object-100-bytes)
89
+ - [`open on "media": the service ignored the range and gave no Content-Length, so a suffix range cannot be cut: the end of the object is not known`](#open-on-media-the-service-ignored-the-range-and-gave-no-content-length-so-a-suffix-range-cannot-be-cut-the-end-of-the-object-is-not-known)
90
+ - **The service**
91
+ - [`Missing S3 credentials. 'accessKeyId', 'secretAccessKey', 'bucket', and 'endpoint' are required`](#missing-s3-credentials-accesskeyid-secretaccesskey-bucket-and-endpoint-are-required)
92
+ - [`The AWS Access Key Id you provided does not exist in our records.`](#the-aws-access-key-id-you-provided-does-not-exist-in-our-records)
93
+ - [`Your proposed upload exceeds the maximum allowed object size.`](#your-proposed-upload-exceeds-the-maximum-allowed-object-size)
94
+ - [`Your proposed upload is smaller than the minimum allowed object size.`](#your-proposed-upload-is-smaller-than-the-minimum-allowed-object-size)
95
+ - [`Invalid according to Policy: Policy Condition failed`](#invalid-according-to-policy-policy-condition-failed)
96
+ - [`Invalid according to Policy: Policy expired`](#invalid-according-to-policy-policy-expired)
97
+ - [A presigned upload stored a body the bucket would have refused](#a-presigned-upload-stored-a-body-the-bucket-would-have-refused)
98
+ - [A listing came back short with a cursor still set](#a-listing-came-back-short-with-a-cursor-still-set)
99
+
100
+ ## Install and import
101
+
102
+ ### `Cannot find package 'bun'`
103
+
104
+ **When:** importing `@softistx/s3` under Node — the full line names the file it
105
+ was imported from.
106
+ **Why:** the client is Bun's own `S3Client`, which is why there is no AWS SDK
107
+ to install and why this package does not run on Node. Measured on Node 22.
108
+ **Fix:**
109
+
110
+ ```sh
111
+ bun run ./src/index.ts # Bun 1.4 or later
112
+ ```
113
+
114
+ ### `Cannot find module 'bun' or its corresponding type declarations.`
115
+
116
+ **When:** typechecking, on the first file that imports `@softistx/s3`.
117
+ **Why:** the shipped declarations import `S3Client`, `S3File` and `S3Options`
118
+ from `bun`, so your project needs Bun's types. They are not a dependency of
119
+ this package.
120
+ **Fix:**
121
+
122
+ ```sh
123
+ bun add -d @types/bun
124
+ ```
125
+
126
+ ## Configuration
127
+
128
+ ### `defineBucket: a bucket definition needs a bucket`
129
+
130
+ **When:** at `defineBucket`, with an empty `bucket`.
131
+ **Why:** the bucket name is what every key is written under; an empty one
132
+ cannot be meant.
133
+ **Fix:**
134
+
135
+ ```ts
136
+ export const avatars = defineBucket({
137
+ bucket: 'avatars',
138
+ key: (p: { userId: string }) => `${p.userId}.png`,
139
+ });
140
+ ```
141
+
142
+ ### `defineBucket: "avatars" has a maxSize of 0; it is a number of bytes, and must be above zero`
143
+
144
+ **When:** at `defineBucket`.
145
+ **Why:** `maxSize` is a number of **bytes**, and it is inclusive: 1024 passes
146
+ and 1025 does not. A string body is measured in bytes, not in characters.
147
+ **Fix:**
148
+
149
+ ```ts
150
+ defineBucket({ bucket: 'avatars', key, maxSize: 2 * 1024 * 1024 });
151
+ ```
152
+
153
+ ### `defineBucket: "avatars" accepts an empty list of content types, so nothing could ever be written. …`
154
+
155
+ **When:** at `defineBucket`, with `contentType: []`.
156
+ **Why:** an empty list refuses every write. The message ends with the way out,
157
+ ``Leave `contentType` out to accept anything``: leaving the option out is what
158
+ accepts anything, and `[]` is never what was meant.
159
+ **Fix:**
160
+
161
+ ```ts
162
+ defineBucket({ bucket: 'avatars', key, contentType: ['image/png', 'image/jpeg'] });
163
+ ```
164
+
165
+ ### ``parseKey on "files": the definition has no `parseKey`; add one next to `key` ``
166
+
167
+ **When:** at `store.parseKey(key)`, on a bucket whose `defineBucket` gave no
168
+ `parseKey`. A `TypeError`, thrown on the call, not at `bindBucket`.
169
+ **Why:** the package cannot invert a `key` function it cannot read, so it does
170
+ not guess.
171
+ **Fix:** write the inverse beside `key`; return `undefined` for a key that is
172
+ not the bucket's:
173
+
174
+ ```ts
175
+ defineBucket({
176
+ bucket: 'files',
177
+ key: (p: { id: string }) => `items/${p.id}`,
178
+ parseKey: (key) => {
179
+ const id = /^items\/([0-9a-f-]+)$/.exec(key)?.[1];
180
+ return id === undefined ? undefined : { id };
181
+ },
182
+ });
183
+ ```
184
+
185
+ ## Service and network failures
186
+
187
+ ### The bucket cannot be reached
188
+
189
+ A call fails with a network code (`ConnectionRefused`, `ECONNREFUSED`,
190
+ `ETIMEDOUT`, `DNSResolveFailed`, …), with this package's `TIMEOUT`, or with an
191
+ S3 service code that means the deployment cannot use the bucket
192
+ (`AccessDenied`, `InvalidAccessKeyId`, `SignatureDoesNotMatch`,
193
+ `NoSuchBucket`, `ExpiredToken`, `InternalError`, `ServiceUnavailable`,
194
+ `SlowDown`). Test for it with `isBucketUnavailable(error)` and answer 503;
195
+ let every other error through. A refusal of the caller's input (`TOO_LARGE`,
196
+ `WRONG_TYPE`, …) and a per-request code such as `NoSuchKey` are `false`.
197
+
198
+ ```ts
199
+ import { isBucketUnavailable } from '@softistx/s3';
200
+
201
+ try {
202
+ await avatars.put(key, body);
203
+ } catch (error) {
204
+ if (isBucketUnavailable(error)) return new Response(null, { status: 503 });
205
+ throw error;
206
+ }
207
+ ```
208
+
209
+ ## Writes refused before they are sent
210
+
211
+ ### `"avatars" accepts image/png, image/jpeg, not the type given (put on "avatars")`
212
+
213
+ **When:** `put`, with a `type` the definition does not list. A presigned URL
214
+ is never checked against it — `PresignOptions` has no `type`, and a signed
215
+ PUT constrains the key and the deadline and nothing else.
216
+ **Why:** an `S3Error` with `code: 'WRONG_TYPE'`. Nothing was sent. The
217
+ message lists what the bucket accepts and never quotes the type it was given
218
+ — before 0.4.0 it ended `not application/pdf`. The type
219
+ is compared on its **essence**: `text/csv` accepts `text/csv;charset=utf-8`
220
+ and `TEXT/CSV`, because that is what real bodies carry — parameters and case
221
+ are ignored, nothing else is.
222
+ **Fix:**
223
+
224
+ ```ts
225
+ import { S3Error } from '@softistx/s3';
226
+
227
+ try {
228
+ await avatars.put({ userId }, body, { type: file.type });
229
+ } catch (error) {
230
+ if (error instanceof S3Error && error.code === 'WRONG_TYPE') return badRequest();
231
+ throw error;
232
+ }
233
+ ```
234
+
235
+ ### ``"avatars" accepts image/png, image/jpeg, and no content type was named. Pass `type` (put on "avatars")``
236
+
237
+ **When:** `put` on a bucket with `contentType`, for a body that carries no
238
+ type of its own — a string, a typed array, a stream.
239
+ **Why:** the guard cannot accept what it cannot read, so an unnamed type is
240
+ refused rather than guessed. `code: 'WRONG_TYPE'`. Before 0.4.0 it read
241
+ ``… and this write names no content type. Pass `type` ``.
242
+ **Fix:**
243
+
244
+ ```ts
245
+ await avatars.put({ userId }, bytes, { type: 'image/png' });
246
+ ```
247
+
248
+ `Bun.file(path)` carries its own type, and does not need the option.
249
+
250
+ ### `"avatars" accepts 2097152 bytes at most, and this body is 5242880 (put on "avatars")`
251
+
252
+ **When:** `put`, for a body whose size is known and above `maxSize`.
253
+ **Why:** an `S3Error` with `code: 'TOO_LARGE'`, raised before the request goes
254
+ out.
255
+ **Fix:**
256
+
257
+ ```ts
258
+ if (error instanceof S3Error && error.code === 'TOO_LARGE') return payloadTooLarge();
259
+ ```
260
+
261
+ ### `"avatars" has a maxSize, and this body's size cannot be known before sending it. …`
262
+
263
+ **When:** `put` with `maxSize` set, for a `Response`, a `Request`, a stream or
264
+ another `S3File`.
265
+ **Why:** nothing can check a length it has not read — an `S3File` reports its
266
+ size as `NaN` until the service has been asked — so the write is refused
267
+ rather than streamed unchecked. `code: 'UNMEASURABLE'`. The message ends with
268
+ the two ways out, ``Read it into memory first, or drop `maxSize` and let the
269
+ service refuse it``. For a stream there is a third.
270
+ **Fix:**
271
+
272
+ ```ts
273
+ await avatars.put({ userId }, await response.bytes()); // read it in first
274
+ // or, for a stream, declare its length and keep it streaming:
275
+ await avatars.put({ userId }, stream, { type: 'image/png', size });
276
+ ```
277
+
278
+ Or drop `maxSize` from the definition and let the service refuse an oversized
279
+ body.
280
+
281
+ ### `the stream ended after 100 bytes, short of the declared size of 150 bytes; the upload was aborted and nothing is stored (put on "avatars")`
282
+
283
+ **When:** `put(params, stream, { size })` where the stream gave fewer bytes
284
+ than `size`. The same error reads `the stream has more bytes than the declared
285
+ size of 150 bytes; …` when it gave more.
286
+ **Why:** `size` is sent as the object's `Content-Length` and held to: a body of
287
+ another length is not the object the caller meant, so the transfer is aborted,
288
+ the source is cancelled, and S3 keeps nothing. `code: 'SIZE_MISMATCH'`, raised
289
+ after the request went out. Typical causes: a `Content-Length` header that
290
+ lies, or a `size` computed before the file changed. A client that
291
+ disconnects mid-upload is [`SOURCE_FAILED`](#the-stream-failed-after-40-bytes-the-upload-was-aborted-and-nothing-is-stored-put-on-avatars)
292
+ when the source throws, and `SIZE_MISMATCH` (short) when it just ends.
293
+ **Fix:** declare the length the stream really has — a file's `size`, the
294
+ request's `Content-Length` — and answer the caller's mistake with a 400:
295
+
296
+ ```ts
297
+ if (error instanceof S3Error && error.code === 'SIZE_MISMATCH') return badRequest();
298
+ ```
299
+
300
+ ### `the stream failed after 40 bytes; the upload was aborted and nothing is stored (put on "avatars")`
301
+
302
+ **When:** `put(params, stream, { size })` whose source threw part-way — a
303
+ request body whose client disconnected, a file that vanished — or gave a chunk
304
+ that is not bytes (`the stream gave a string, not bytes after 4 bytes; …`).
305
+ **Why:** the transfer cannot be completed, so it is aborted, the source is
306
+ cancelled and S3 keeps nothing. `code: 'SOURCE_FAILED'`, raised after the
307
+ request went out, with the source's own error as `cause`. It is not a failure
308
+ of the service: `isBucketUnavailable` is `false`.
309
+ **Fix:** answer the caller, who went away or sent bad data, and read the
310
+ `cause` for the reason:
311
+
312
+ ```ts
313
+ if (error instanceof S3Error && error.code === 'SOURCE_FAILED') {
314
+ console.warn('upload interrupted', error.cause);
315
+ return badRequest();
316
+ }
317
+ ```
318
+
319
+ ### `size is a whole number of bytes, 0 or more; got a fraction (put on "avatars")`
320
+
321
+ **When:** a `size` that is negative, a fraction, `NaN` or not a number. The
322
+ other two refusals of the same code: `size goes with a ReadableStream or an
323
+ AsyncIterable body; …` (a string, bytes or a `Blob` know their length) and
324
+ `an AsyncIterable body needs `size` …`.
325
+ **Fix:** pass `size` as whole bytes with a stream, and leave it off for a
326
+ string, bytes or a `Blob`. `code: 'WRONG_OPTION'`, before anything is sent.
327
+
328
+ ### `storageClass must be one of STANDARD, DEEP_ARCHIVE, EXPRESS_ONEZONE, …; got another string (put on "avatars")`
329
+
330
+ The whole line names every class the service takes, then the **shape** of
331
+ what it was given — `another string`, `a number`, `null` — never the value:
332
+
333
+ ```text
334
+ storageClass must be one of STANDARD, DEEP_ARCHIVE, EXPRESS_ONEZONE, GLACIER,
335
+ GLACIER_IR, INTELLIGENT_TIERING, ONEZONE_IA, OUTPOSTS, REDUCED_REDUNDANCY,
336
+ SNOW, STANDARD_IA; got another string (put on "avatars")
337
+ ```
338
+
339
+ Before 0.4.0 it quoted the value: `got "CHEAP"`.
340
+
341
+ **When:** `put` with a `storageClass` that is not one of those — usually a
342
+ value read off a request body or an environment variable, where the types
343
+ were not there to refuse it.
344
+ **Why:** an `S3Error` with `code: 'WRONG_OPTION'`, raised before the request
345
+ goes out, like the content type and the size. Since 0.3.0 this package
346
+ checks the two guarded options itself rather than letting the client refuse
347
+ them, so one `catch` covers every refusal of a `put`.
348
+ **Fix:** narrow the value against the option's own type before it reaches the
349
+ call:
350
+
351
+ ```ts
352
+ import { S3Error, type PutOptions } from '@softistx/s3';
353
+
354
+ // the classes this application allows, proved against the option's type
355
+ const CLASSES = ['STANDARD', 'STANDARD_IA'] as const satisfies readonly NonNullable<
356
+ PutOptions['storageClass']
357
+ >[];
358
+
359
+ function storageClassOf(value: string | undefined): PutOptions['storageClass'] {
360
+ return CLASSES.find((known) => known === value); // undefined: the bucket's default
361
+ }
362
+
363
+ try {
364
+ await avatars.put({ userId }, bytes, { storageClass: storageClassOf(input) });
365
+ } catch (error) {
366
+ if (error instanceof S3Error && error.code === 'WRONG_OPTION') return badRequest();
367
+ throw error;
368
+ }
369
+ ```
370
+
371
+ ### `acl must be one of private, public-read, public-read-write, …; got another string (put on "avatars")`
372
+
373
+ ```text
374
+ acl must be one of private, public-read, public-read-write, aws-exec-read,
375
+ authenticated-read, bucket-owner-read, bucket-owner-full-control,
376
+ log-delivery-write; got another string (put on "avatars")
377
+ ```
378
+
379
+ From a presigned call the line ends with that call instead: `…; got another
380
+ string (presignPut on "avatars")`.
381
+
382
+ **When:** `put`, `presignGet`, `presignPut` or `presignPost` with an `acl` that is not one
383
+ of those. Both paths go through the same allowlist since 0.3.0; before it,
384
+ `presign` handed the value to the client, which refused it with a plain
385
+ `TypeError` that quoted **every accepted value** (`must be one of "private",
386
+ "public-read", …`), so a message with the allowed values in quotes means the
387
+ package is older than 0.3.0. From 0.3.0 to 0.4.0 this one quoted the value it
388
+ was given (`got "everyone"`); it now gives only its shape.
389
+ **Why:** the same `code: 'WRONG_OPTION'`, before anything is sent or signed.
390
+ The guarded options are `acl` and `storageClass` (a fixed set each) and
391
+ `contentDisposition` (one printable-ASCII header value); `contentEncoding` is a
392
+ plain string to the service and accepts anything.
393
+ `presignGet`, `presignPut` and `presignPost` take no `storageClass` —
394
+ nothing is stored by signing a URL or a form.
395
+ **Fix:**
396
+
397
+ ```ts
398
+ await avatars.put({ userId }, bytes, { acl: 'public-read' });
399
+ const url = avatars.presignPut({ userId }, { acl: 'private', expiresIn: 300 });
400
+ ```
401
+
402
+ ### `contentDisposition must be a non-empty string of printable ASCII, with no line break or control character (spell a non-ASCII filename as filename*=UTF-8''...); got a string with other characters (presignGet on "avatars")`
403
+
404
+ **When:** `put`, `presignGet` or `presignPost` with a `contentDisposition`
405
+ that is empty, not a string, or holds a character outside space-to-tilde:
406
+ a CR, LF or NUL, a tab, an accented letter. `got` names the shape (`an empty string`,
407
+ `a string with other characters`, or for a non-string `a number`,
408
+ `an object`, `null`, `undefined`…), never the value, and the line ends with
409
+ the call. `presignPut` takes no `contentDisposition` at all. A `put` refuses
410
+ it too since 0.5.0; before it, any string went through to the service.
411
+ **Why:** an `S3Error` with `code: 'WRONG_OPTION'`, raised before anything is
412
+ sent or signed. The value becomes a header, and a line break in it would split
413
+ that header.
414
+ **Fix:** printable ASCII, with a non-ASCII filename spelled as RFC 6266's
415
+ `filename*`:
416
+
417
+ ```ts
418
+ const url = avatars.presignGet(
419
+ { userId },
420
+ { expiresIn: 300, contentDisposition: "attachment; filename*=UTF-8''%C3%A9t%C3%A9.png" },
421
+ );
422
+ ```
423
+
424
+ ### `expiresIn is seconds, and must be above 0 and at most 604800 (seven days, which is S3's own limit); got a number above that (presignGet on "avatars")`
425
+
426
+ **When:** `presignGet`, `presignPut` or `presignPost` with an `expiresIn`
427
+ that is not a finite number of seconds inside S3's range. Only the
428
+ presigned calls take one, so the line always ends with the call —
429
+ `(presignGet on "avatars")`, `(presignPut on …)` or `(presignPost on …)` —
430
+ and `got` names the shape: `a number above that`,
431
+ `zero`, `a negative number`, `NaN`, `a string`. Before 0.4.0 it quoted the
432
+ value (`got 1000000000000`).
433
+ **Why:** an `S3Error` with `code: 'WRONG_OPTION'`, raised before anything is
434
+ signed. Measured on bun 1.4.2, the client refuses `0` and below with a
435
+ `TypeError` of its own and **signs** `1e12` happily — a URL the service then
436
+ rejects when somebody uses it, long after this package reported success.
437
+ **Fix:** pass seconds, and no more than a week:
438
+
439
+ ```ts
440
+ const url = avatars.presignPut({ userId }, { expiresIn: 300 }); // five minutes
441
+ ```
442
+
443
+ Sign for the time the page actually needs: a day is a long life for a URL
444
+ anyone can forward.
445
+
446
+ ## Presigned URLs refused by the service
447
+
448
+ ### `SignatureDoesNotMatch` on a presigned URL behind a proxy
449
+
450
+ **When:** a browser opens a `presignGet`, `presignPut` or `presignPost` URL and
451
+ the service answers `403 SignatureDoesNotMatch`. The URL was signed for one
452
+ host and reached the service as another.
453
+ **Why:** the signature covers the `Host`. Either the URL was signed for
454
+ `endpoint` (an internal address) rather than the origin the browser uses, or the
455
+ proxy rewrites `Host` before forwarding.
456
+ **Fix:** bind with `publicEndpoint`, the origin browsers reach, and make the
457
+ proxy pass the `Host` header through unchanged:
458
+
459
+ ```ts
460
+ const store = bindBucket(avatars, {
461
+ endpoint: 'http://minio:9000',
462
+ publicEndpoint: 'https://media.example.com',
463
+ accessKeyId: process.env.S3_KEY,
464
+ secretAccessKey: process.env.S3_SECRET,
465
+ });
466
+ ```
467
+
468
+ ## Presigned POSTs refused before they are signed
469
+
470
+ Every entry here comes from `presignPost`, raised before anything is signed,
471
+ so no form was handed out. The refusals of an option or a type are
472
+ `S3Error`s; the option values usually come off a request body, so answer
473
+ `WRONG_OPTION` and `WRONG_TYPE` with a 400. The last three entries are not:
474
+ two `TypeError`s when this package's secret is not Bun's, and a plain `Error`
475
+ when the URL Bun signed cannot be read — none of them is the caller's input,
476
+ so answer them with a 500. Every
477
+ message reports the **shape** of what it was given — `a string`,
478
+ `a fraction`, `the type given` — never the value. An `acl` or an `expiresIn`
479
+ refused here is the entry above, ending with `(presignPost on "avatars")`.
480
+
481
+ ### ``presignPost on "uploads": this bucket has no maxSize, and a presigned POST is a bound on what a browser uploads. Pass `maxSize`, in bytes``
482
+
483
+ **When:** `presignPost` on a bucket whose definition has no `maxSize`, with
484
+ no `maxSize` in the options. `code: 'WRONG_OPTION'`.
485
+ **Why:** the size range is what a POST has over a PUT. A form with no upper
486
+ bound would be a presigned PUT with extra steps, so this package will not sign
487
+ one.
488
+ **Fix:** pass one, or give the definition a `maxSize` for every upload:
489
+
490
+ ```ts
491
+ const form = uploads.presignPost(params, { maxSize: 10 * 1024 * 1024 });
492
+ ```
493
+
494
+ ### `presignPost on "avatars": maxSize cannot be above the bucket's own 2097152 bytes; got a larger number`
495
+
496
+ **When:** a `maxSize` above the definition's. `code: 'WRONG_OPTION'`.
497
+ **Why:** an option can tighten the bucket's bound, never loosen it — a `put`
498
+ of the same body would be refused.
499
+ **Fix:** leave `maxSize` out to take the bucket's, or pass a smaller one.
500
+
501
+ ### `presignPost on "avatars": maxSize is a whole number of bytes, at least 1; got a string`
502
+
503
+ **When:** a `maxSize` or a `minSize` that is not a whole number of bytes —
504
+ for `minSize` the same message says `at least 0`, and `got` names the shape:
505
+ `a string`, `zero`, `a fraction`, `a negative number`, `NaN`.
506
+ `code: 'WRONG_OPTION'`.
507
+ **Why:** `content-length-range` is a count of bytes, and a value off a request
508
+ body is not one until it has been checked.
509
+ **Fix:** check it is an integer before passing it, or keep sizes out of the
510
+ request and choose them on the server.
511
+
512
+ ### `presignPost on "avatars": minSize is above maxSize, so no body could be posted`
513
+
514
+ **When:** `minSize` greater than `maxSize` (the one given, or the bucket's).
515
+ `code: 'WRONG_OPTION'`.
516
+ **Why:** the service would refuse every upload, so the form is not signed.
517
+ **Fix:** `minSize` at most `maxSize`; leave it out for `0`.
518
+
519
+ ### ``presignPost on "avatars": this bucket accepts image/png, image/jpeg, and a prefix would let another type through. Pass one of them as `type` ``
520
+
521
+ **When:** `type: { startsWith }` on a bucket whose definition names its
522
+ content types. `code: 'WRONG_TYPE'`.
523
+ **Why:** `image/` would let `image/gif` through a bucket that accepts two
524
+ image types. A prefix is for a bucket that names none.
525
+ **Fix:** sign for the type the browser will send:
526
+
527
+ ```ts
528
+ const form = avatars.presignPost({ userId }, { type: file.type });
529
+ ```
530
+
531
+ ### `presignPost on "uploads": type is a content type or { startsWith }; got a number`
532
+
533
+ **When:** a `type` that is neither a non-empty string nor an object with a
534
+ string `startsWith` — `got` names its shape. `code: 'WRONG_OPTION'`.
535
+ **Why:** it becomes a policy condition; anything else has no meaning there.
536
+ **Fix:** `type: 'image/png'`, or `type: { startsWith: 'image/' }` on a bucket
537
+ that names no type.
538
+
539
+ ### `"avatars" accepts image/png, image/jpeg, not the type given (presignPost on "avatars")`
540
+
541
+ **When:** `presignPost` with a `type` the bucket does not accept — or, as
542
+ ``… and no content type was named. Pass `type` (presignPost on "avatars")``, with no
543
+ `type` on a bucket that names **several**. `code: 'WRONG_TYPE'`: the same
544
+ refusal a `put` gives, with the call named at the end.
545
+ **Why:** the policy holds one type. With a single type in the definition it
546
+ is the default; with several, the caller says which one this upload is.
547
+ **Fix:**
548
+
549
+ ```ts
550
+ const form = avatars.presignPost({ userId }, { type: 'image/jpeg' });
551
+ ```
552
+
553
+ ### `presignPost on "avatars": the secret access key this package would sign with is not the one Bun signs with, so the service would refuse the form. …`
554
+
555
+ The three entries on the signer — this one and the two after it — are also
556
+ raised by a `list` under a deadline, which signs its own request with the same
557
+ signer: the message then starts `list on "avatars": …` and says `request` where
558
+ it says `form`.
559
+
560
+ The whole line:
561
+
562
+ ```text
563
+ presignPost on "avatars": the secret access key this package would sign with
564
+ is not the one Bun signs with, so the service would refuse the form. Bun reads
565
+ S3_SECRET_ACCESS_KEY and AWS_SECRET_ACCESS_KEY when the process starts; one
566
+ changed since is not the one Bun uses. Pass `secretAccessKey` to bindBucket
567
+ ```
568
+
569
+ **When:** `presignPost` on a bucket bound **without** a `secretAccessKey` option, after `S3_SECRET_ACCESS_KEY` (or `AWS_SECRET_ACCESS_KEY`) was changed
570
+ while the process was running. A `TypeError`, not an `S3Error`: nothing a
571
+ request sent is wrong.
572
+ **Why:** Bun reads those variables **once, when the process starts**, and
573
+ keeps signing with what it read; this package reads them when the bucket is
574
+ bound. A form signed with the new secret would pass every check here and be
575
+ refused by the service only when a browser posts it. So `presignPost` checks
576
+ its secret against the signature Bun itself put on a throwaway URL, and
577
+ refuses before signing anything when they differ — measured in a process
578
+ started with the variable set, in
579
+ [`post-signer.spec.ts`](https://github.com/softistx/data/blob/develop/packages/s3/src/bucket/operations/post-signer.spec.ts).
580
+ **Fix:** pass the secret to `bindBucket` rather than changing the environment
581
+ of a running process:
582
+
583
+ ```ts
584
+ const store = bindBucket(avatars, {
585
+ endpoint: process.env.S3_ENDPOINT,
586
+ accessKeyId: process.env.S3_KEY,
587
+ secretAccessKey: process.env.S3_SECRET,
588
+ });
589
+ ```
590
+
591
+ ### `presignPost on "avatars": no secret access key to sign with, while Bun has one. …`
592
+
593
+ **When:** as above, when the variable was **deleted** after the process
594
+ started: Bun still signs with the secret it read then, and this package has
595
+ none. A `TypeError`, measured the same way.
596
+ **Why:** a POST policy is signed with the secret, and Bun's client never hands
597
+ its own back. This package keeps it beside the bucket's context, never on
598
+ it, so printing the context, the bucket or the form never shows it —
599
+ measured with a marker secret, in
600
+ [`post-signer.spec.ts`](https://github.com/softistx/data/blob/develop/packages/s3/src/bucket/operations/post-signer.spec.ts). With no secret anywhere,
601
+ Bun's own `ERR_S3_MISSING_CREDENTIALS` comes first (next section).
602
+ **Fix:** give `bindBucket` a `secretAccessKey`.
603
+
604
+ ### `presignPost on "avatars": the URL Bun signed has no credential scope, or not the key at the end of its path, so there is nowhere to post the form. …`
605
+
606
+ **When:** only with a Bun that signs a presigned URL differently from the
607
+ 1.4.2 this package was measured on, or with an access key id holding a `%`
608
+ that is not an escape (`AK%zz`): Bun writes the id into the URL unencoded, so
609
+ it cannot be read back. A plain `Error`, not an `S3Error`. An access key id
610
+ with a `=`, a `&`, a space or a non-ASCII character is not supported either:
611
+ Bun's own presigned URL is malformed for it.
612
+ **Why:** `presignPost` asks Bun where the bucket is by signing a throwaway
613
+ key (`nxgt-probe`) and reading the URL: the bucket's URL is the path before
614
+ that key, and the region and access key are in `X-Amz-Credential`. A URL
615
+ without either would post the form somewhere else, or sign it as nobody, so
616
+ it is refused rather than guessed.
617
+ **Fix:** use Bun 1.4.2, the version this package was measured on, and
618
+ [open an issue](https://github.com/softistx/data/issues) naming the Bun version that produced it.
619
+
620
+ ## Testing
621
+
622
+ Errors of `@softistx/s3/testing`; see the [testing guide](guide/testing.md).
623
+
624
+ ### `WEED_BIN is /nowhere/weed, which does not exist`
625
+
626
+ **When:** `startTestS3()` or `seaweedfsBinary()`, with `$WEED_BIN` set.
627
+ **Why:** `$WEED_BIN` names a file that is not there. It is used before the
628
+ cache, so a stale value in your shell or CI hides the downloaded binary.
629
+ **Fix:** point it at a `weed` that exists, or unset it:
630
+
631
+ ```sh
632
+ unset WEED_BIN
633
+ ```
634
+
635
+ ### `binary is /nowhere/weed, which does not exist`
636
+
637
+ **When:** `startTestS3({ binary })`.
638
+ **Why:** the `binary` option wins over `$WEED_BIN` and the cache, and it names
639
+ a missing file.
640
+ **Fix:** pass a path that exists, or leave `binary` out.
641
+
642
+ ### `No SeaweedFS binary for win32/x64: install one and set WEED_BIN to its path.`
643
+
644
+ **When:** the first run, on a platform and architecture the SeaweedFS release
645
+ does not ship (Windows, and 32-bit ARM macOS), with nothing cached.
646
+ **Why:** `startTestS3` downloads a release asset named for `process.platform`
647
+ and `process.arch`, and there is none for this one.
648
+ **Fix:** install or build `weed` yourself and name it:
649
+
650
+ ```sh
651
+ WEED_BIN=/usr/local/bin/weed bun test
652
+ ```
653
+
654
+ ### `SeaweedFS 4.47 linux_amd64.tar.gz has SHA-256 …, expected …: refusing to run it.`
655
+
656
+ **When:** the first run, downloading SeaweedFS.
657
+ **Why:** the archive is not the one this version of `@softistx/s3` pins. A proxy
658
+ that rewrites downloads, a truncated transfer, or a release asset replaced
659
+ upstream all end here. Nothing was unpacked or cached.
660
+ **Fix:** retry on a clean connection; behind a proxy that serves its own
661
+ copy, install `weed` and set `$WEED_BIN`. If the release itself changed,
662
+ that is a bug to report: do not bypass the check.
663
+
664
+ ### `No pinned SHA-256 for SeaweedFS 4.47 plan9_amd64.tar.gz: refusing to run an unchecked download.`
665
+
666
+ **When:** the first run; the asset the platform maps to has no pinned hash.
667
+ **Why:** a table and a platform mapping that disagree, which this package's
668
+ own spec rules out for the shipped platforms.
669
+ **Fix:** set `$WEED_BIN`, and report the platform.
670
+
671
+ ### `GET https://github.com/seaweedfs/seaweedfs/releases/download/4.47/linux_amd64.tar.gz answered 404`
672
+
673
+ **When:** the first run, downloading SeaweedFS.
674
+ **Why:** GitHub did not serve the asset: the network is down or filtered, a
675
+ rate limit answered, or the release was withdrawn. A dropped connection
676
+ (including one cut while the archive is read), a 5xx and a 429 are retried
677
+ four times with a growing pause before this error; a 404 and a checksum
678
+ mismatch are not retried.
679
+ **Fix:** retry; in a sandbox without network, download once elsewhere and
680
+ cache `~/.cache/nxgt/seaweedfs` (or `$XDG_CACHE_HOME/nxgt/seaweedfs`), or set `$WEED_BIN`.
681
+
682
+ ### `GET https://github.com/seaweedfs/seaweedfs/releases/download/4.47/linux_amd64.tar.gz failed: read ECONNRESET`
683
+
684
+ **When:** the first run, downloading SeaweedFS.
685
+ **Why:** the connection dropped, while connecting or while the archive was
686
+ read, on all four tries (a 5xx or a 429 on every try ends as `answered 503`
687
+ or `answered 429` instead).
688
+ **Fix:** rerun on a stable connection; behind a flaky proxy or in a sandbox,
689
+ install `weed` and set `$WEED_BIN`, or cache
690
+ `~/.cache/nxgt/seaweedfs` (or `$XDG_CACHE_HOME/nxgt/seaweedfs`).
691
+
692
+ ### `SeaweedFS did not serve S3 on http://127.0.0.1:24561 in 90s (bucket "avatars"). Its log, …/weed.log, says:`
693
+
694
+ **When:** `startTestS3()` or `createBucket(name)`.
695
+ **Why:** the process started but never took a write. The message ends with
696
+ the interesting lines of its own log: a taken port, a binary that dies on
697
+ start, a disk with no room for the volumes it allocates.
698
+ **Fix:** read those lines first. A machine under heavy load can also need
699
+ longer than 90 s; stop other test servers, and give `beforeAll` a timeout of
700
+ 120 s or more. To fail sooner with an `S3Error` `TIMEOUT`, pass
701
+ `createBucket(name, { timeoutMs })`.
702
+
703
+ ### `reset (list) on "avatars": the test S3 server gave no answer in 3000ms; it is stuck`
704
+
705
+ **When:** `reset(bucket, { timeoutMs })` or `createBucket(name, { timeoutMs })`
706
+ from `@softistx/s3/testing`. The error is an `S3Error` coded `TIMEOUT`. The
707
+ message starts with the call that was waiting: `reset (list)`, `reset
708
+ (delete)` or `createBucket`; `createBucket` can also end with `did not take a
709
+ write in <n>ms. Its log, <path>, says:` followed by the server's log.
710
+ **Why:** the test server accepted the connection and did not answer within
711
+ `timeoutMs`: it is stuck, or the machine is too loaded.
712
+ **Fix:** when the message quotes the server's log (`createBucket` only, when
713
+ the server answered with errors), read it; stop other test servers, and restart. Raise `timeoutMs` only if the
714
+ machine is slow, and keep it under your hook timeout. On `createBucket` the
715
+ number in the message can be the time left of the total, not `timeoutMs`.
716
+
717
+ ### `createBucket: "x" is not a bucket name S3 accepts: 3 to 63 characters, lowercase letters, digits, dots and hyphens, starting and ending with a letter or digit`
718
+
719
+ **When:** `createBucket(name)`.
720
+ **Why:** SeaweedFS refuses every write to a bucket whose name breaks S3's
721
+ rules, so without this check the call would retry for 90 s and time out.
722
+ **Fix:** name the bucket within the rules (`avatars`, `user-uploads`).
723
+
724
+ ### `no free block of 8 consecutive ports`
725
+
726
+ **When:** `startTestS3()`.
727
+ **Why:** SeaweedFS binds eight ports (four services, each with a gRPC port),
728
+ and fifty random blocks between 20000 and 30000 all had one taken.
729
+ **Fix:** stop what holds ports in that range, or run fewer servers at once.
730
+
731
+ ## Deadlines
732
+
733
+ ### `timeoutMs is a whole number of milliseconds, 1 or more; got a fraction (stat on "avatars")`
734
+
735
+ **When:** a `timeoutMs` that is zero, negative, a fraction, `NaN` or not a
736
+ number, on `stat`, `exists`, `bytes`, `slice`, `open`, `text` or `delete`. `code:
737
+ 'WRONG_OPTION'`, thrown before anything is sent. On `bindBucket` the same
738
+ mistake is wiring, not a request: a bare `TypeError` reading `bindBucket on
739
+ "avatars": timeoutMs is a whole number of milliseconds, 1 or more; got …`.
740
+ **Fix:** pass whole milliseconds, 1 or more: `{ timeoutMs: 5000 }`.
741
+
742
+ ### `bindBucket on "avatars": publicEndpoint is an absolute URL such as https://media.example.com; got a string`
743
+
744
+ **When:** `bindBucket` got a non-empty `publicEndpoint` that does not parse as a
745
+ URL (`'media.example.com'`, a path). A bare `TypeError`: wiring, not a
746
+ request, like the `timeoutMs` one above.
747
+ **Fix:** give the whole origin, scheme included:
748
+ `publicEndpoint: 'https://media.example.com'`. Read it from configuration and
749
+ leave it `undefined` when there is none.
750
+
751
+ ### `bindBucket on "avatars": publicEndpoint is an absolute URL such as https://media.example.com; got an empty string`
752
+
753
+ **When:** `bindBucket` got `publicEndpoint: ''`, typically an environment
754
+ variable that is set but empty. A bare `TypeError`, thrown at bind time, like
755
+ the entry above.
756
+ **Fix:** pass the origin, or leave the option out. Turn an empty value into
757
+ `undefined` where it is read: `publicEndpoint: env.S3_PUBLIC_ENDPOINT || undefined`.
758
+
759
+ ### `stat on "avatars": no answer in 5000ms`
760
+
761
+ **When:** a call with a `timeoutMs` — its own or the bucket's — got no answer
762
+ in time. The message starts with the call: `put`, `stat`, `exists`, `bytes`, `slice`,
763
+ `open`, `text`, `delete` or `list` (`put on "avatars": no answer in 5000ms`).
764
+ `code: 'TIMEOUT'`; the message names the call and the bucket, and the `key` is
765
+ on the error (empty for a `list`, which is about no one key).
766
+ **Why:** the service is down, unreachable, or accepts the connection and never
767
+ answers. The request was **aborted**, but it had been **sent**: a `delete`
768
+ may have happened, and a `put` may have stored the object, all the same. A
769
+ `put` is also cut when the bucket's default, sized for reads, is shorter than
770
+ the upload: the deadline covers the whole body, and a stream is first read into
771
+ memory inside it.
772
+ A **streamed** `put` (with a `size`) is different: see
773
+ [`put on "avatars": nothing moved in 300ms`](#put-on-avatars-nothing-moved-in-300ms).
774
+
775
+ On `open` the deadline covers the time to the response headers only: a body
776
+ that then streams slowly is never cut by it.
777
+ **Fix:** retry if the call is safe to repeat, or raise the deadline — a large
778
+ `put` wants its own, `store.put(params, body, { type, timeoutMs: 120_000 })`. Without a
779
+ `timeoutMs`, a non-streamed call waits 360 s (a streamed `put` is always sent
780
+ with `fetch` and has no such wait) and fails with Bun's own error, named
781
+ `S3Error` too, with `code: 'Timeout'` — test `error instanceof S3Error`, then
782
+ `code`.
783
+
784
+ ```ts
785
+ if (error instanceof S3Error && error.code === 'TIMEOUT') retryLater();
786
+ ```
787
+
788
+ ### `put on "avatars": nothing moved in 300ms`
789
+
790
+ **When:** a streamed `put` (with a `size`) and its own `timeoutMs`. `code:
791
+ 'TIMEOUT'`; nothing is stored, unless the timeout came after the last byte,
792
+ while waiting for the service's answer: the object may then be stored, so check
793
+ with `stat` before retrying.
794
+ **Why:** `timeoutMs` is an **idle** deadline here. It fires only when nothing
795
+ moved for that long: the connection did not come up, the source gave no chunk,
796
+ the service took none, or it did not answer after the last byte. A slow
797
+ transfer that keeps moving is never cut, and the bucket's default `timeoutMs`
798
+ does not apply. The source was cancelled.
799
+ **Fix:** look at the source first: a client that stopped sending is the usual
800
+ cause. Raise `timeoutMs` only if one wait is legitimately longer.
801
+
802
+ ## Reads with `open`
803
+
804
+ ### `range is { start, end? } with 0 <= start < end, or { suffix } with suffix >= 1, as whole numbers; … (open on "media")`
805
+
806
+ **When:** `open` with a `range` that is not an object, or whose numbers are not
807
+ whole, or `end <= start`, or `suffix` below 1, or a `suffix` given with a
808
+ `start` or an `end`. `code: 'WRONG_OPTION'`, thrown before anything is sent.
809
+ **Why:** unlike `slice`, which allows `start === end` (an empty stream), an
810
+ `open` range must hold at least one byte: `start < end`.
811
+ **Fix:** pass `{ start, end }`, `{ start }` or `{ suffix }`; an HTTP
812
+ `Range: bytes=a-b` is `{ start: a, end: b + 1 }`.
813
+
814
+ ### `open on "media": the range starts at or past the end of the object (100 bytes)`
815
+
816
+ **When:** `open(params, { range })` with a `start` at or past the end of the
817
+ object, or any range of an empty object. `code: 'RANGE_NOT_SATISFIABLE'`; the
818
+ service answered 416, and `error.objectSize` is the object's size in bytes when the service said it
819
+ (it is absent otherwise, and on every other error). Nothing is read, and it is
820
+ a harmless read: nothing was changed.
821
+ **Why:** there is no byte to serve in that range. A `start` inside the object
822
+ with an `end` past it is not this error: the range is cut at the object.
823
+ **Fix:** answer 416 with the size, or ask for a range inside the object.
824
+
825
+ ```ts
826
+ if (error instanceof S3Error && error.code === 'RANGE_NOT_SATISFIABLE') {
827
+ return new Response(null, {
828
+ status: 416,
829
+ headers: {
830
+ ...(error.objectSize === undefined
831
+ ? {}
832
+ : { 'content-range': `bytes */${error.objectSize}` }),
833
+ },
834
+ });
835
+ }
836
+ ```
837
+
838
+ ### `open on "media": the service ignored the range and gave no Content-Length, so a suffix range cannot be cut: the end of the object is not known`
839
+
840
+ **When:** `open(params, { range: { suffix } })` against a service that ignores
841
+ `Range`, answers 200 and sends the body chunked, with no `Content-Length`.
842
+ `code: 'RANGE_NOT_SATISFIABLE'`, with no `error.objectSize`.
843
+ **Why:** the last bytes of an object cannot be cut from a stream whose length
844
+ is not known until it ends. A `{ start, end? }` range does not have this
845
+ limit: it is cut while streaming.
846
+ **Fix:** use a service that honours `Range` (S3 and SeaweedFS do), or call
847
+ `stat` first and ask for `{ start: size - n }`.
848
+
849
+ ## The service
850
+
851
+ ### `Missing S3 credentials. 'accessKeyId', 'secretAccessKey', 'bucket', and 'endpoint' are required`
852
+
853
+ **When:** the first call, when neither `bindBucket`'s options nor the
854
+ environment gave the client credentials. Bun's error, `code:
855
+ 'ERR_S3_MISSING_CREDENTIALS'` — from `presignPost` too, which asks Bun where
856
+ the bucket is before it signs.
857
+ **Why:** `bindBucket` creates the `S3Client` for you and passes your options
858
+ through; with none, Bun falls back to the environment, and to AWS's endpoint.
859
+ **Fix:**
860
+
861
+ ```ts
862
+ export const avatars = bindBucket(avatarsDefinition, {
863
+ endpoint: process.env.S3_ENDPOINT,
864
+ accessKeyId: process.env.S3_KEY,
865
+ secretAccessKey: process.env.S3_SECRET,
866
+ virtualHostedStyle: false, // for a service that is not AWS
867
+ });
868
+ ```
869
+
870
+ ### `The AWS Access Key Id you provided does not exist in our records.`
871
+
872
+ **When:** the first call, with credentials the service refuses — or with no
873
+ `endpoint`, which sends the request to AWS whatever your service is.
874
+ **Why:** it is the **service's** answer, raised by Bun as an error whose
875
+ `name` is `S3Error` and whose `code` is the S3 code (`InvalidAccessKeyId`,
876
+ `SignatureDoesNotMatch`, `NoSuchBucket`, `AccessDenied`). It is **not** this
877
+ package's `S3Error` class: `instanceof S3Error` is false for it.
878
+ **Fix:**
879
+
880
+ ```ts
881
+ try {
882
+ await avatars.put({ userId }, bytes);
883
+ } catch (error) {
884
+ if (error instanceof S3Error) return badRequest(error.code); // ours: the guards
885
+ throw error; // the service's, or Bun's: log the code it carries
886
+ }
887
+ ```
888
+
889
+ `bytes`, `slice`, `text` and `stat` are the exception: they turn S3's own `NoSuchKey`
890
+ into `undefined`, so `undefined` means "no such object" and nothing else.
891
+ Every other failure comes back as the error it is.
892
+
893
+ ### `Your proposed upload exceeds the maximum allowed object size.`
894
+
895
+ **When:** a browser posted a `presignPost` form with a file over its
896
+ `maxSize`. The service answers `400`, `<Code>EntityTooLarge</Code>` —
897
+ measured on SeaweedFS 4.47 — and stores nothing.
898
+ **Why:** that is the policy's `content-length-range` doing its job. `maxSize`
899
+ is inclusive: exactly `maxSize` bytes is stored.
900
+ **Fix:** nothing to fix on the server. Check `file.size` in the browser
901
+ before posting to spare the user the round trip, and show the 400 as "too
902
+ big".
903
+
904
+ ### `Your proposed upload is smaller than the minimum allowed object size.`
905
+
906
+ **When:** a posted file under the form's `minSize`. `400`,
907
+ `<Code>EntityTooSmall</Code>`, measured on SeaweedFS 4.47.
908
+ **Why:** `content-length-range`'s lower end.
909
+ **Fix:** leave `minSize` out (it is `0`), or check the size in the browser.
910
+
911
+ ### `Invalid according to Policy: Policy Condition failed`
912
+
913
+ **When:** a posted form whose fields do not match the policy. `403`,
914
+ `<Code>AccessDenied</Code>`, measured on SeaweedFS 4.47 for each of: another
915
+ `Content-Type`, the same type in another case (`IMAGE/PNG`) or with a
916
+ parameter (`;charset=utf-8`), another `key`, another `acl`, and a
917
+ `Content-Type` field missing when the policy fixes one or holds it to a
918
+ prefix. A bucket that names no type, signed with no `type`, is the exception:
919
+ its form posts with no `Content-Type` field — measured, `204`, stored as
920
+ `application/octet-stream`.
921
+ **Why:** the policy compares each field **exactly**. The usual cause is code
922
+ that rebuilds the form instead of posting `fields` as given — or a
923
+ `{ startsWith }` form posted without the browser's own `Content-Type` field.
924
+ **Fix:**
925
+
926
+ ```ts
927
+ const body = new FormData();
928
+ for (const [name, value] of Object.entries(form.fields)) body.append(name, value);
929
+ // with { startsWith }: body.append('Content-Type', file.type);
930
+ body.append('file', file); // last
931
+ ```
932
+
933
+ A field the policy does not name is refused too, with its own message —
934
+ measured, `Invalid according to Policy: Extra input fields: X-Amz-Meta-Foo`.
935
+ Do not add fields to the form.
936
+
937
+ ### `Invalid according to Policy: Policy expired`
938
+
939
+ **When:** a form posted after its `expiresIn`. `403`,
940
+ `<Code>AccessDenied</Code>`, measured on SeaweedFS 4.47.
941
+ **Why:** the policy's `expiration` is part of what was signed.
942
+ **Fix:** sign the form when the user starts the upload, not when the page
943
+ loads, and keep `expiresIn` close to how long an upload takes.
944
+
945
+ ### A presigned upload stored a body the bucket would have refused
946
+
947
+ **When:** after handing out a `presignPut` URL. No error anywhere.
948
+ **Why:** a presigned PUT constrains the key and the deadline, and nothing
949
+ else. Measured on Bun 1.4: `X-Amz-SignedHeaders` stays `host`, so the
950
+ uploader's `Content-Type` is never signed and the size is never checked —
951
+ which is why `presignPut` takes no `type` at all. The guards are `put`'s;
952
+ `file(params).writer()` and `client` are Bun's own and write whatever they
953
+ are given.
954
+ **Fix:** use a presigned POST, whose policy the service enforces — a body
955
+ over `maxSize` or of another type is refused before it is stored:
956
+
957
+ ```ts
958
+ const form = avatars.presignPost({ userId }, { type: 'image/png', expiresIn: 300 });
959
+ ```
960
+
961
+ With a `presignPut` you are keeping, check what actually landed:
962
+
963
+ ```ts
964
+ const stat = await avatars.stat({ userId });
965
+ if (!stat || stat.size > maxSize) await avatars.delete({ userId });
966
+ ```
967
+
968
+ ### A listing came back short with a cursor still set
969
+
970
+ **When:** `list`, on an eventually consistent service.
971
+ **Why:** `limit` is a maximum, not a promise.
972
+ **Fix:**
973
+
974
+ ```ts
975
+ let cursor: string | null = null;
976
+ do {
977
+ const page = await avatars.list({ prefix, limit: 100, cursor });
978
+ cursor = page.nextCursor;
979
+ } while (cursor !== null);
980
+ ```
981
+
982
+ Page until `nextCursor` is `null`, never until a page is short.