#11011 `wrangler vectorize list --json` outputs invalid json
Bug confirmed in code and reproduction. logger.log() called unconditionally in list.ts and listMetadataIndex.ts before JSON output. Same bug fixed for list-vectors in PR #10517 but not applied to these commands.
Apply same fix pattern from PR #10517: wrap logger.log() in if (!args.json) condition
Analysis Report
Issue Review: cloudflare/workers-sdk#11011
Summary
wrangler vectorize list --json and wrangler vectorize list-metadata-index --json output a log message before the JSON, making the output invalid JSON.
Findings
- Created: 2025-10-19
- Updated: 2025-10-19
- Version: 4.43.0 → 4.60.0 (current)
- Component: wrangler / vectorize
- Labels: bug
- Comments: 0
Key Evidence
Source code confirms the bug is still present:
list.ts:24-logger.log()is called unconditionally before JSON outputlistMetadataIndex.ts:23- Same issue,logger.log()is unconditional
Related issue #10508 was fixed for
list-vectorsin PR #10517 (2025-09-03):- The fix in
listVectors.tswraps the log inif (!args.json)- this pattern was not applied tolist.tsorlistMetadataIndex.ts
- The fix in
Reproduction confirmed: Running
npx wrangler vectorize list --jsonoutputs📋 Listing Vectorize indexes...before the JSONNo PRs or changelog entries address this issue
Recommendation
Status: KEEP OPEN
Reasoning: The bug is confirmed to still exist in the latest version (4.60.0). A similar fix was applied to listVectors.ts in PR #10517 but was not extended to list.ts and listMetadataIndex.ts. The fix is straightforward and follows an established pattern.
Action: Apply the same fix pattern from PR #10517 to list.ts and listMetadataIndex.ts
Root Cause Analysis
The bug occurs because logger.log() is called unconditionally in both commands, regardless of whether --json flag is set.
packages/wrangler/src/vectorize/list.ts:24
async handler(args, { config }) {
logger.log(`📋 Listing Vectorize indexes...`); // BUG: Always prints
const indexes = await listIndexes(config, args.deprecatedV1);
packages/wrangler/src/vectorize/listMetadataIndex.ts:23
async handler(args, { config }) {
logger.log(`📋 Fetching metadata indexes...`); // BUG: Always prints
const res = await listMetadataIndex(config, args.name);
Comparison with fixed listVectors.ts:47-49 (from PR #10517):
async handler(args, { config }) {
if (!args.json) {
logger.log(`📋 Listing vectors in index '${args.name}'...`);
}
Proposed Solution
Apply the same conditional pattern used in listVectors.ts:
Fix for list.ts
async handler(args, { config }) {
if (!args.json) {
logger.log(`📋 Listing Vectorize indexes...`);
}
const indexes = await listIndexes(config, args.deprecatedV1);
Fix for listMetadataIndex.ts
async handler(args, { config }) {
if (!args.json) {
logger.log(`📋 Fetching metadata indexes...`);
}
const res = await listMetadataIndex(config, args.name);
Implementation Details
Difficulty: Easy
Justification:
- Single-line change in each file (wrap existing log in conditional)
- Exact pattern already exists in
listVectors.tsfrom PR #10517 - No architectural changes needed
- Tests already exist for the vectorize commands
Files to Modify
packages/wrangler/src/vectorize/list.ts- Line 24packages/wrangler/src/vectorize/listMetadataIndex.ts- Line 23
Testing Recommendations
Add/update tests in
packages/wrangler/src/__tests__/vectorize/vectorize.test.tsto verify:vectorize list --jsonoutputs valid JSON (no preceding text)vectorize list-metadata-index <name> --jsonoutputs valid JSON- Without
--json, the log message still appears
Manual verification:
wrangler vectorize list --json | jq . # Should parse without error wrangler vectorize list-metadata-index my-index --json | jq .
Notes & Feedback (0)
No notes yet.