Repository navigation
fix(r2): tolerate missing httpMetadata/customMetadata on listed objects - #1098
Open
PedroRosalba wants to merge 1 commit into
Open
PedroRosalba wants to merge 1 commit into
PedroRosalba wants to merge 1 commit into
Conversation
Since the `r2_list_honor_include` compatibility flag (2022-08-04) workerd only attaches `httpMetadata` and `customMetadata` to objects returned by `bucket.list()` when the listing asked for them through `include`. Both are optional in workers-types, but the worker-sys getters declared them required, so `Object::http_metadata()` panicked in `From<R2HttpMetadata> for HttpMetadata` (unwrap of a TypeError reading `contentType` of `undefined`) and `Object::custom_metadata()` would feed `undefined` to `Object.keys`. The getters now return `Option`; `http_metadata()` yields an empty `HttpMetadata` and `custom_metadata()` an empty map when the runtime omitted the field. Public signatures are unchanged. Miniflare's R2 backend still sends the fields as empty objects, so the new test documents the behaviour on both shapes; the panic was reproduced by making the backend omit empty metadata, as real R2 does.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Since the
r2_list_honor_includecompatibility flag (2022-08-04), workerd only attacheshttpMetadataandcustomMetadatato objects returned bybucket.list()when the listing asked for them throughinclude. Both are optional in workers-types, but the worker-sys getters declare them required, soObject::http_metadata()panics inFrom<R2HttpMetadata> for HttpMetadata(unwrap of a TypeError readingcontentTypeofundefined) andObject::custom_metadata()feedsundefinedtoObject.keys.Fix
The getters return
Option;http_metadata()yields an emptyHttpMetadataandcustom_metadata()an empty map when the runtime omitted the field. Public signatures are unchanged.Tests
Miniflare's R2 backend still sends the fields as empty objects, so the committed test documents the behaviour on that shape and passes on
mainas well. The panic was reproduced by patching the local Miniflare backend to omit empty metadata, as production R2 does, and the fix was verified against that patched backend. The bug is visible in the workerd source forR2Bucket::list.Tested on macOS (Apple Silicon) only.