Skip to content

Conversation

osarogie
Copy link

@osarogie osarogie commented Sep 8, 2025

Removes serialization that wraps the metadata (that's already a string) in quotes.
These quote caused Metadata.parse to fail with the following error: "Metadata string is not valid"

Closes #791

Copy link

changeset-bot bot commented Sep 8, 2025

🦋 Changeset detected

Latest commit: a224979

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@tus/azure-store Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

coderabbitai bot commented Sep 8, 2025

Walkthrough

Changed AzureStore.getMetadata to parse raw upload.metadata directly with Metadata.parse(upload.metadata) when present, and set it to an empty object when absent; removed the prior JSON.stringify wrapper.

Changes

Cohort / File(s) Summary
Azure Store metadata parsing
packages/azure-store/src/index.ts
In getMetadata, replaced upload.metadata = Metadata.parse(JSON.stringify(upload.metadata ?? {})) with upload.metadata = upload.metadata ? Metadata.parse(upload.metadata) : {}. No public API changes.
Release metadata
.changeset/small-pillows-hug.md
Added a changeset indicating a patch release for @tus/azure-store with description "Fix metadata parsing bug." No code behavior changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title Check ✅ Passed The title "@tus/azure-store: fix metadata parsing bug" is concise, names the affected package, and directly summarizes the primary change (removing incorrect serialization that broke metadata parsing), so it accurately reflects the main change in the PR.
Linked Issues Check ✅ Passed The change implements the fix described in issue #791 by removing JSON.stringify(upload.metadata ?? {}) and instead parsing the raw upload.metadata or defaulting to {}, which addresses the "Metadata string is not valid" error; the raw_summary and PR objectives confirm the diff matches the issue's suggested patch.
Out of Scope Changes Check ✅ Passed The only code change is in packages/azure-store/src/index.ts (plus an added .changeset file), both of which are directly related to the metadata parsing fix described in the linked issue; there are no unrelated file modifications in the provided summary.
Description Check ✅ Passed The PR description explains that JSON.stringify wrapping of upload.metadata was removed because it caused Metadata.parse to fail and references the error and linked issue, which directly matches the implemented code change.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d3706e2 and a224979.

📒 Files selected for processing (1)
  • .changeset/small-pillows-hug.md (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .changeset/small-pillows-hug.md

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
packages/azure-store/src/index.ts (3)

118-121: Make parsing resilient to unexpected shapes and parse errors

Defend against cases where upload.metadata might already be an object (older records/tests) or an invalid string. Fallback to {} instead of throwing.

Apply:

-    upload.metadata = upload.metadata ? Metadata.parse(upload.metadata) : {}
+    try {
+      if (typeof upload.metadata === 'string' && upload.metadata.length > 0) {
+        upload.metadata = Metadata.parse(upload.metadata)
+      } else if (upload.metadata && typeof upload.metadata === 'object') {
+        // already parsed; keep as-is
+      } else {
+        upload.metadata = {}
+      }
+    } catch (e) {
+      log('Invalid TUS metadata string; defaulting to {}', e as Error)
+      upload.metadata = {}
+    }

71-73: Typos in docstring

“metada” → “metadata”, “everytime” → “every time”.

-   * Saves upload metadata to blob metada. Also upload metadata
-   * gets saved in local cache as well to avoid calling azure server everytime.
+   * Saves upload metadata to blob metadata. Also saves it
+   * in local cache to avoid calling the Azure service every time.

145-156: Optional: add a targeted test to prevent regressions

Consider adding an AzureStore metadata round‑trip test (including non‑ASCII and null values) similar to packages/utils/src/test/stores.ts to lock this fix.

I can draft a minimal test that creates an upload with metadata {filename: '世界.pdf', is_confidential: null}, persists it, reads it back, and deepStrictEquals the metadata. Want me to open a follow‑up PR with that?

📜 Review details

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 227d9ff and 3e8b295.

📒 Files selected for processing (1)
  • packages/azure-store/src/index.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/azure-store/src/index.ts (1)
packages/gcs-store/src/index.ts (1)
  • upload (172-180)
🔇 Additional comments (1)
packages/azure-store/src/index.ts (1)

118-121: Good fix: parse the raw TUS metadata string instead of JSON-stringifying it

This removes the extra quoting that broke Metadata.parse and restores round‑trip symmetry with saveMetadata’s Metadata.stringify.

@Murderlon
Copy link
Member

CI is failing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@tus/azure-store: Cannot download file

2 participants