Skip to content

@tus/azure-store: fix metadata parsing bug#790

Open
osarogie wants to merge 5 commits intotus:mainfrom
osarogie:patch-1
Open

@tus/azure-store: fix metadata parsing bug#790
osarogie wants to merge 5 commits intotus:mainfrom
osarogie:patch-1

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

@changeset-bot
Copy link

changeset-bot bot commented Sep 8, 2025

🦋 Changeset detected

Latest commit: 5461fc0

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

@coderabbitai
Copy link

coderabbitai bot commented Sep 8, 2025

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Changed AzureStore.getMetadata to robustly handle upload.metadata as either a base64/string value, an object, or missing: if it's a string parse directly with Metadata.parse, if it's an object stringify then parse, and if absent default to an empty object. Replaced the previous unconditional JSON.stringify wrapper.

Changes

Cohort / File(s) Summary
Azure Store metadata parsing
packages/azure-store/src/index.ts
Updated getMetadata to branch on upload.metadata type: parse when it's a string, stringify-then-parse when it's an object, or use {} when missing. Removed the prior unconditional Metadata.parse(JSON.stringify(...)) usage.
Release metadata
.changeset/small-pillows-hug.md
Added a changeset for a patch release of the azure store package with message "Fix metadata parsing bug."

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: fixing a metadata parsing bug in @tus/azure-store.
Description check ✅ Passed The description explains the bug, its cause, and the solution, directly related to the changeset and linked issue.
Linked Issues check ✅ Passed The changes directly address issue #791 by removing JSON.stringify wrapping of metadata before parsing, allowing Metadata.parse to handle the raw base64-encoded string correctly.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the metadata parsing bug described in issue #791; no out-of-scope modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

@Murderlon
Copy link
Member

ping

@osarogie osarogie closed this Feb 24, 2026
@osarogie osarogie deleted the patch-1 branch February 24, 2026 12:27
@osarogie osarogie restored the patch-1 branch February 24, 2026 12:27
@osarogie osarogie reopened this Feb 24, 2026
@osarogie
Copy link
Author

Apologies for the delay @Murderlon. I've fix the bug

Comment on lines +120 to +128
let metadataStr
if (typeof upload.metadata === 'string') {
metadataStr = upload.metadata
} else if (upload.metadata && typeof upload.metadata === 'object') {
metadataStr = JSON.stringify(upload.metadata ?? {})
} else {
metadataStr = '{}'
}
upload.metadata = Metadata.parse(metadataStr)
Copy link
Member

Choose a reason for hiding this comment

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

This is overprotective for no reason? It should be as simple as this? Maybe undefined instead of {} not sure.

Suggested change
let metadataStr
if (typeof upload.metadata === 'string') {
metadataStr = upload.metadata
} else if (upload.metadata && typeof upload.metadata === 'object') {
metadataStr = JSON.stringify(upload.metadata ?? {})
} else {
metadataStr = '{}'
}
upload.metadata = Metadata.parse(metadataStr)
upload.metadata = upload.metadata ? Metadata.parse(JSON.stringify(upload.metadata)) : {}

Copy link
Author

Choose a reason for hiding this comment

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

There were cases when upload.metadata was already a string.
That's why I added this check

    if (typeof upload.metadata === 'string') {
      metadataStr = upload.metadata
    }

I could simplify it to look like this

    let metadataStr
    if (typeof upload.metadata === 'string') {
      metadataStr = upload.metadata
    } else if (upload.metadata && typeof upload.metadata === 'object') {
      metadataStr = JSON.stringify(upload.metadata ?? {})
    }
    upload.metadata = metadataStr ? Metadata.parse(metadataStr) : {}

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