Skip to content

fix(wrangler): vectorize list and list-metadata-index should output valid json#12807

Open
MaxwellCalkin wants to merge 1 commit intocloudflare:mainfrom
MaxwellCalkin:fix/vectorize-list-json-output
Open

fix(wrangler): vectorize list and list-metadata-index should output valid json#12807
MaxwellCalkin wants to merge 1 commit intocloudflare:mainfrom
MaxwellCalkin:fix/vectorize-list-json-output

Conversation

@MaxwellCalkin
Copy link

@MaxwellCalkin MaxwellCalkin commented Mar 8, 2026

Fixes #11011.

Follows the same pattern as PR #10517 (which fixed list-vectors --json for #10508).

Problem

wrangler vectorize list --json and wrangler vectorize list-metadata-index --json print a human-readable log message before the JSON output:

📋 Listing Vectorize indexes...
[
  { ... }
]

This makes stdout invalid JSON and breaks piping to jq and other tools.

Fix

Wrap the logger.log() calls in if (!args.json) guards so the log message is suppressed when --json is used — the same one-line pattern applied in #10517 for list-vectors.

list.ts:

-		logger.log(`📋 Listing Vectorize indexes...`);
+		if (!args.json) {
+			logger.log(`📋 Listing Vectorize indexes...`);
+		}

listMetadataIndex.ts:

-		logger.log(`📋 Fetching metadata indexes...`);
+		if (!args.json) {
+			logger.log(`📋 Fetching metadata indexes...`);
+		}

  • Tests
    • Tests included
    • Tests not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: bugfix
  • Wrangler V3 Backport
    • Wrangler PR:
    • Not necessary because: v4 only

Open with Devin

…alid json

Wrap the log messages in `if (!args.json)` guards so that
`wrangler vectorize list --json` and
`wrangler vectorize list-metadata-index --json` output only valid JSON
without a preceding human-readable log line.

Follows the same pattern used in PR cloudflare#10517 for list-vectors.
@MaxwellCalkin MaxwellCalkin requested a review from a team as a code owner March 8, 2026 11:16
@changeset-bot
Copy link

changeset-bot bot commented Mar 8, 2026

🦋 Changeset detected

Latest commit: 0820900

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

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

@workers-devprod
Copy link
Contributor

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • packages/wrangler/src/tests/vectorize/vectorize.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/vectorize/list.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/vectorize/listMetadataIndex.ts: [@cloudflare/wrangler]

Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 2 potential issues.

View 2 additional findings in Devin Review.

Open in Devin Review

}
const indexes = await listIndexes(config, args.deprecatedV1);

if (indexes.length === 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

🔴 Empty index list with --json flag outputs no JSON instead of []

When wrangler vectorize list --json is called and there are no indexes, the empty-check at packages/wrangler/src/vectorize/list.ts:33 runs before the JSON output at line 43. This causes the handler to log a warning via logger.warn() and return early without ever outputting JSON. A caller expecting valid JSON on stdout will get an empty string, which is not valid JSON. The fix should move the args.json check before the empty-length check, or output [] for the empty case when --json is set.

(Refers to lines 33-41)

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

}
const res = await listMetadataIndex(config, args.name);

if (res.metadataIndexes.length === 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

🔴 Empty metadata index list with --json flag outputs no JSON instead of []

When wrangler vectorize list-metadata-index <name> --json is called and there are no metadata indexes, the empty-check at packages/wrangler/src/vectorize/listMetadataIndex.ts:34 runs before the JSON output at line 44. This causes the handler to log a warning via logger.warn() and return early without ever outputting JSON. A caller expecting valid JSON on stdout will get an empty string, which is not valid JSON. The fix should move the args.json check before the empty-length check, or output [] for the empty case when --json is set.

(Refers to lines 34-42)

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

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.

wrangler vectorize list --json and list-metadata-index --json output a log/message (not valid json)

2 participants