Skip to content

fix(cli): fail closed when messages get targets a nonexistent channel - #6449

Open
sanjay3290 wants to merge 1 commit into
block:mainfrom
sanjay3290:fix/messages-get-fail-closed
Open

fix(cli): fail closed when messages get targets a nonexistent channel#6449
sanjay3290 wants to merge 1 commit into
block:mainfrom
sanjay3290:fix/messages-get-fail-closed

Conversation

@sanjay3290

Copy link
Copy Markdown

Fixes #6389.

Problem

buzz messages get --channel <uuid> prints [] and exits 0 when the channel does not exist or the caller is not a member. That is indistinguishable from a channel with no messages, so scripts cannot tell "no messages yet" from "wrong UUID".

Change

cmd_get_messages probes for the channel's kind:39000 discovery event by #d before querying messages. If the probe returns no event, it returns CliError::NotFound, which exits 1.

This also covers the unauthorized case from the issue: kind:39000 events are stored channel-scoped, so a non-member's probe comes back empty and the command fails closed rather than reporting an empty history.

The probe filter matches the one cmd_get_channel already uses in crates/buzz-cli/src/commands/channels.rs.

Before / after

$ buzz messages get --channel 00000000-0000-4000-8000-000000000000 --limit 1
[]
$ echo $?
0
$ buzz messages get --channel 00000000-0000-4000-8000-000000000000 --limit 1
error: channel '00000000-0000-4000-8000-000000000000' not found
$ echo $?
1

Tests

Two unit tests in crates/buzz-cli/src/commands/messages.rs, each against a local stub relay:

  • cmd_get_messages_fails_when_channel_not_found — probe returns [], expect CliError::NotFound
  • cmd_get_messages_succeeds_when_channel_exists — probe returns a kind:39000 event, expect Ok and the messages printed

The first test fails on main with expected NotFound, got Ok(()).

Verification

Run on this branch, rebased on 24ec6a4:

cargo clippy --workspace --all-targets -- -D warnings   # exit 0
cargo fmt --all -- --check                              # exit 0
cargo test -p buzz-cli --lib                            # 365 passed, 0 failed

Notes

  • Costs one extra relay query per messages get. That seemed the right trade for a correct exit code, but I am happy to gate it behind a flag if you would rather not pay it on the hot path.
  • Scoped to messages get only. messages thread, channels members, and canvas get have the same silent-empty behaviour and are left alone here.

Signed-off-by: Sanjay Ramadugu <sramadugu1@gmail.com>
Co-authored-by: Sanjay Ramadugu <sramadugu1@gmail.com>
@sanjay3290
sanjay3290 requested a review from a team as a code owner August 21, 2026 03:54
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.

messages get on a nonexistent channel returns [] with exit 0

1 participant