fix(wrangler): vectorize list and list-metadata-index should output valid json#12807
fix(wrangler): vectorize list and list-metadata-index should output valid json#12807MaxwellCalkin wants to merge 1 commit intocloudflare:mainfrom
Conversation
…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.
🦋 Changeset detectedLatest 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 |
|
Codeowners approval required for this PR:
Show detailed file reviewers
|
| } | ||
| const indexes = await listIndexes(config, args.deprecatedV1); | ||
|
|
||
| if (indexes.length === 0) { |
There was a problem hiding this comment.
🔴 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)
Was this helpful? React with 👍 or 👎 to provide feedback.
| } | ||
| const res = await listMetadataIndex(config, args.name); | ||
|
|
||
| if (res.metadataIndexes.length === 0) { |
There was a problem hiding this comment.
🔴 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)
Was this helpful? React with 👍 or 👎 to provide feedback.
Fixes #11011.
Follows the same pattern as PR #10517 (which fixed
list-vectors --jsonfor #10508).Problem
wrangler vectorize list --jsonandwrangler vectorize list-metadata-index --jsonprint a human-readable log message before the JSON output:This makes stdout invalid JSON and breaks piping to
jqand other tools.Fix
Wrap the
logger.log()calls inif (!args.json)guards so the log message is suppressed when--jsonis used — the same one-line pattern applied in #10517 forlist-vectors.list.ts:listMetadataIndex.ts: