Skip to content

fix(wrangler): suppress log messages when --json flag is used in vectorize commands#12477

Open
kaigritun wants to merge 4 commits intocloudflare:mainfrom
kaigritun:fix/vectorize-json-output-log-messages
Open

fix(wrangler): suppress log messages when --json flag is used in vectorize commands#12477
kaigritun wants to merge 4 commits intocloudflare:mainfrom
kaigritun:fix/vectorize-json-output-log-messages

Conversation

@kaigritun
Copy link

@kaigritun kaigritun commented Feb 7, 2026

Summary

When using --json flag on vectorize list, list-metadata-index, and info commands, the output included log messages (e.g. 📋 Listing Vectorize indexes...) that made the stdout invalid JSON, breaking piping to tools like jq.

Changes

Wrap progress log messages in a condition to check for !args.json, following the pattern already established in listVectors.ts (lines 49-51).

Files modified:

  • packages/wrangler/src/vectorize/list.ts
  • packages/wrangler/src/vectorize/listMetadataIndex.ts
  • packages/wrangler/src/vectorize/info.ts

Before

$ wrangler vectorize list --json
📋 Listing Vectorize indexes...
[{"name": "test-index", ...}]

After

$ wrangler vectorize list --json
[{"name": "test-index", ...}]

Fixes #11011

  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: This is basically a bug fix.

Open with Devin

…orize commands

When using --json flag on vectorize list, list-metadata-index, and info commands, the output included log messages (e.g. '📋 Listing Vectorize indexes...') that made the stdout invalid JSON, breaking piping to tools like jq.

This fix wraps these log messages in a condition to check for !args.json, following the pattern already established in listVectors.ts.

Fixes cloudflare#11011
@kaigritun kaigritun requested a review from a team as a code owner February 7, 2026 17:52
@changeset-bot
Copy link

changeset-bot bot commented Feb 7, 2026

🦋 Changeset detected

Latest commit: 0d6f85f

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

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 3 additional findings in Devin Review.

Open in Devin Review

Move the json output check before the empty-length check to ensure
that when --json flag is used and results are empty, we output []
instead of returning early with a warning message.

Fixes review feedback on PR cloudflare#12477
Copy link
Author

@kaigritun kaigritun left a comment

Choose a reason for hiding this comment

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

Thanks for the detailed review! I've addressed both issues by moving the args.json check before the empty-length check in both list.ts and listMetadataIndex.ts.

Now when --json flag is used:

  • Empty indexes will output [] instead of showing a warning and returning early
  • This ensures wrangler vectorize list --json | jq . will work correctly even with no results

Changes pushed in commit 1dc6a08.

Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

This looks good. We'll need some tests to prove it out and a changeset before we can land it.

@github-project-automation github-project-automation bot moved this from Untriaged to In Review in workers-sdk Feb 12, 2026
@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 12, 2026

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@12477

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@12477

miniflare

npm i https://pkg.pr.new/miniflare@12477

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@12477

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@12477

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@12477

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@12477

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@12477

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@12477

wrangler

npm i https://pkg.pr.new/wrangler@12477

commit: 763cac7

- Add tests for --json flag with empty results in vectorize list
- Add tests for --json flag with empty results in list-metadata-index
- Add changeset documenting the patch fix

Addresses review feedback from Pete Bacon Darwin on PR cloudflare#12477
@kaigritun
Copy link
Author

Thanks Pete! I've added:

  1. Changeset: .changeset/fix-vectorize-json-empty-output.md - documenting this as a patch fix
  2. Tests: Added two new test cases following the existing patterns:
    • should output clean JSON when there are no vectorize indexes with --json flag (line ~382)
    • should output clean JSON when there are no metadata indexes with --json flag (line ~889)

Both tests verify that:

  • Empty results output clean JSON ([]) without warnings
  • No warning messages are mixed into stdout when --json is used

Pushed in commit 763cac7. Ready for review!

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 1 new potential issue.

⚠️ 1 issue in files not directly in the diff

⚠️ listVectors --json with empty results outputs warning instead of clean JSON (packages/wrangler/src/vectorize/listVectors.ts:64-67)

The listVectors.ts handler has the same bug that this PR fixes in list.ts and listMetadataIndex.ts, but it was not fixed here. When --json is used and the result is empty, the empty-check at line 64 fires first, logging a warning via logger.warn and returning — the args.json check at line 69 is never reached.

Root Cause and Impact

In packages/wrangler/src/vectorize/listVectors.ts:64-67, the empty vectors check runs before the JSON output check at lines 69-72:

if (result.vectors.length === 0) {
    logger.warn("No vectors found in this index.");
    return;
}

if (args.json) {
    logger.log(JSON.stringify(result, null, 2));
    return;
}

When a user runs wrangler vectorize list-vectors my-index --json and the index has no vectors, they get a warning message on stderr and no JSON on stdout, instead of clean JSON output. This is the exact same bug pattern that this PR correctly fixes in list.ts (line 33-36) and listMetadataIndex.ts (line 34-37) by moving the args.json check before the empty check.

Impact: Users piping wrangler vectorize list-vectors --json to tools like jq will get no stdout output when the index is empty, breaking automation pipelines.

View 3 additional findings in Devin Review.

Open in Devin Review

Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

I think the latest Devin review issue (that listVectors has the same problem) should be fixed in this PR too.
Also we have a logger.json() helper that we should use.

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 1 new potential issue.

⚠️ 1 issue in files not directly in the diff

⚠️ listVectors --json with empty results outputs warning instead of clean JSON (packages/wrangler/src/vectorize/listVectors.ts:64-67)

The listVectors.ts handler has the same bug that this PR fixes in list.ts and listMetadataIndex.ts, but it was not fixed here. When --json is used and the result is empty, the empty-check at line 64 fires first, logging a warning via logger.warn and returning — the args.json check at line 69 is never reached.

Root Cause and Impact

In packages/wrangler/src/vectorize/listVectors.ts:64-67, the empty vectors check runs before the JSON output check at lines 69-72:

if (result.vectors.length === 0) {
    logger.warn("No vectors found in this index.");
    return;
}

if (args.json) {
    logger.log(JSON.stringify(result, null, 2));
    return;
}

When a user runs wrangler vectorize list-vectors my-index --json and the index has no vectors, they get a warning message on stderr and no JSON on stdout, instead of clean JSON output. This is the exact same bug pattern that this PR correctly fixes in list.ts (line 33-36) and listMetadataIndex.ts (line 34-37) by moving the args.json check before the empty check.

Impact: Users piping wrangler vectorize list-vectors --json to tools like jq will get no stdout output when the index is empty, breaking automation pipelines.

View 5 additional findings in Devin Review.

Open in Devin Review

@petebacondarwin
Copy link
Contributor

Can you also take a look at:

⚠️ listVectors --json with empty results outputs warning instead of clean JSON (packages/wrangler/src/vectorize/listVectors.ts:64-67)

The listVectors.ts handler has the same bug that this PR fixes in list.ts and listMetadataIndex.ts, but it was not fixed here. When --json is used and the result is empty, the empty-check at line 64 fires first, logging a warning via logger.warn and returning — the args.json check at line 69 is never reached.

it("should output clean JSON when there are no vectorize indexes with --json flag", async () => {
mockVectorizeV2RequestError();
await runWrangler("vectorize list --json");
expect(std.out).toMatchInlineSnapshot(`"[]"`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a test when there are actual things to list, similar to it("should handle listing vectorize indexes" on l341 above

Copy link
Contributor

Choose a reason for hiding this comment

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

Also using JSON.parse would allow testing that the output is actually valid JSON, i.e.:

expect(JSON.parse(std.out)).toMatchInlineSnapshot();

it("should output clean JSON when there are no metadata indexes with --json flag", async () => {
mockVectorizeV2RequestError();
await runWrangler("vectorize list-metadata-index test-index --json");
expect(std.out).toMatchInlineSnapshot(`"[]"`);
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

@MichaelDeBoey
Copy link
Contributor

MichaelDeBoey commented Feb 16, 2026

I'm not making any claims about the quality of their work, but I wanted to let you know that @kaigritun is a fully-autonomous non-human actor
https://socket.dev/blog/ai-agent-lands-prs-in-major-oss-projects-targets-maintainers-via-cold-outreach

@petebacondarwin
Copy link
Contributor

Thanks @MichaelDeBoey - we saw the blog post 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Review

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)

4 participants

Comments