Skip to content

fix(search): fail when the broker page query fails - #157

Merged
digizeph merged 1 commit into
mainfrom
fix/search-broker-error
Nov 2, 2026
Merged

digizeph merged 1 commit into
mainfrom
fix/search-broker-error

Conversation

@digizeph

@digizeph digizeph commented Nov 2, 2026

Copy link
Copy Markdown
Member

Fixes #156.

Problem

monocle search reported success when the broker API failed. Reported command, against an API that answered HTTP 500:

$ monocle search -t 2019-04-20T00:00:00Z -T 2019-04-21T00:00:00Z -p 1.1.1.0/24 -D rib
$ echo $?
0

No stdout, no stderr. With --debug the only trace was Completed processing across 0 pages.

Cause

The page iterator mapped the broker error onto the end of the iteration:

let items = broker.clone().page(current_page).query_single_page().ok()?;

so "the API failed" and "there are no more files" became the same None, and the command finished as if the result set were empty.

Change

broker_page_iter yields Result<Vec<BrokerItem>, String>: one Err on a failed page, then end of iteration. The search loop records the error, skips the completion log, tears down the writer and progress threads, and exits 1:

$ monocle search -t 2019-04-20T00:00:00Z -T 2019-04-21T00:00:00Z -p 1.1.1.0/24 -D rib
Error: broker query failed (page 1: BrokerError: ...); search aborted.
$ echo $?
1

The regression test serves HTTP 500 from a local TcpListener and asserts the iterator reports one error and then ends; reverting the propagation makes it fail.

Note on the message text: this crate depends on bgpkit-broker 0.10.1, whose client decodes an error body as a success payload and therefore surfaces only error decoding response body. bgpkit/bgpkit-broker#116 reports the HTTP status and body instead, so a dependency bump makes the server's own message visible here without another change to this code.

Verification

  • cargo fmt --check
  • cargo clippy --features cli --bin monocle -- -D warnings
  • cargo test --features cli --bin monocle (21 passed, one new)
  • Rebuilt binary against the live API: the command above exits 1 with the error, while a healthy window (2026-10-20, --broker-files) exits 0 with its 3 files.

The paged file lookup collapsed a broker error into the end of the iterator, so
an HTTP 500 from the API printed nothing (an info line under --debug) and the
command exited 0 with empty output.

Yield the error from broker_page_iter, abort the search, and exit 1 with the
message. Add a regression test that serves an HTTP 500 from a local listener and
asserts the iterator reports one error before ending.
Copilot AI balanced review requested due to automatic review settings November 2, 2026 13:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues block the change to distinguish broker API failures from empty search results.

No open issues 🎉

What changed in this PR

Fixes #156 by making monocle search distinguish broker API failures from empty results, so failed page queries no longer silently exit successfully.

Changes:

  • Propagates broker page errors, suppresses the completion log, and exits with status 1 after writer and progress-thread cleanup.
  • Adds a local HTTP 500 regression test and documents the fix in the changelog.
File Description
src/​bin/​commands/​search.rs Adds page-error propagation, failure handling, and an HTTP 500 regression test.
CHANGELOG.md Documents the corrected search failure behavior under Unreleased changes.

Review effort: Balanced

@digizeph
digizeph merged commit 88b4ee3 into main Nov 2, 2026
2 checks passed
@digizeph
digizeph deleted the fix/search-broker-error branch November 2, 2026 13:08
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.

monocle search treats HTTP 500 error as success

2 participants