Workers SDK Issue Reports

← Back to Dashboard

#11011 `wrangler vectorize list --json` outputs invalid json

Download Reproduction
Recommendation:KEEP OPEN
Difficulty:easy
Reasoning:

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.

Suggested Action:

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

  1. Source code confirms the bug is still present:

    • list.ts:24 - logger.log() is called unconditionally before JSON output
    • listMetadataIndex.ts:23 - Same issue, logger.log() is unconditional
  2. Related issue #10508 was fixed for list-vectors in PR #10517 (2025-09-03):

    • The fix in listVectors.ts wraps the log in if (!args.json) - this pattern was not applied to list.ts or listMetadataIndex.ts
  3. Reproduction confirmed: Running npx wrangler vectorize list --json outputs 📋 Listing Vectorize indexes... before the JSON

  4. No 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.ts from PR #10517
  • No architectural changes needed
  • Tests already exist for the vectorize commands

Files to Modify

  1. packages/wrangler/src/vectorize/list.ts - Line 24
  2. packages/wrangler/src/vectorize/listMetadataIndex.ts - Line 23

Testing Recommendations

  1. Add/update tests in packages/wrangler/src/__tests__/vectorize/vectorize.test.ts to verify:

    • vectorize list --json outputs valid JSON (no preceding text)
    • vectorize list-metadata-index <name> --json outputs valid JSON
    • Without --json, the log message still appears
  2. 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.

Add Note