Skip to content

fix: return an error when --whois is used with a non-domain query - #61

Open
ferhalemre wants to merge 1 commit into
openrdap:mainfrom
ferhalemre:fix/whois-non-domain-exit-code
Open

ferhalemre wants to merge 1 commit into
openrdap:mainfrom
ferhalemre:fix/whois-non-domain-exit-code

Conversation

@ferhalemre

@ferhalemre ferhalemre commented Nov 25, 2026 •

Copy link
Copy Markdown

Fixes #37.

--whois only supports domain objects, but for any other object type (autnum, IP network, entity, ...) the CLI printed nothing and exited 0. Scripts had no way to tell that the output was missing.

This change checks the response type before printing and exits 1 with --whois output is only supported for domain queries when the object is not a domain.

One behaviour to confirm: with --whois --json on a non-domain query the command now fails before printing the JSON as well. If you would rather print the other formats and only warn about --whois, I'm happy to change it.

Tests: three new golden cases (autnum text, autnum --whois, autnum --whois --json). The two --whois cases fail without the fix. go test -race ./... passes.

Disclosure: this change was prepared with an AI coding assistant (Claude Code). The bug was reproduced and the tests were run locally before submitting.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • The CLI can display autonomous system (AS) number query results in text format.
  • Bug Fixes
    • Using --whois with an AS number query now reports that WHOIS output is available only for domain queries and exits with an error status.

--whois only supports domain objects. For any other object type the CLI
printed nothing and exited 0, so scripts could not tell that the output
was missing. Check the response type before printing and exit 1 with an
explanatory message instead.

Fixes openrdap#37

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

When --whois receives a non-domain response, RunCLI prints an error and returns status 1. Golden tests cover successful Autnum text output and failed Autnum WHOIS output in text and JSON modes.

Severity of issue fixed: Low

Merge Risk: Minimal · up to 532ff

The change makes --whois exit with an error for non-domain queries instead of silently succeeding. It is covered by tests and has no identified merge-blocking risk.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed Title ugh, me caveman. Title say: return error when --whois used with non-domain query. Code do exactly that: RunCLI reject --whois output when response not Domain, print error, exit 1. Title is main …
Linked Issues check Passed Issue #37 requires that --whois with a non-domain query (ASN, IP) gives a warning or error and a non-zero exit code. The PR adds a check in RunCLI (cli.go): when the response is not a Domain, it print…
Out of Scope Changes check Passed Changes are: a type check in RunCLI for --whois (cli.go); an autnum fixture route in fixtureServer and three AS64496 golden cases (cli_test.go); and three golden files. All of these serve #37. The fix…
Full details: Title check

Explanation

Title ugh, me caveman. Title say: return error when --whois used with non-domain query. Code do exactly that: RunCLI reject --whois output when response not Domain, print error, exit 1. Title is main change. Objectives match issue #37. Title clear, specific, short. PASS.

Full details: Linked Issues check

Explanation

Issue #37 requires that --whois with a non-domain query (ASN, IP) gives a warning or error and a non-zero exit code. The PR adds a check in RunCLI (cli.go): when the response is not a Domain, it prints an error and returns 1. The text is --whois output is only supported for domain queries. Domain responses still go to the existing WHOIS formatter. Golden tests cover autnum with --whois and --whois --json; both expect exit 1, empty stdout, and that stderr message. The autnum text golden checks that normal output still works. The IP case from #37 is covered by the same type check, per the AI-generated summary. Direct diff reads were unavailable, so the cli.go hunk is based on the summary and the reviewed file read, which was truncated before the output section. Issue #37 is open and has no non-coding requirements. The objective to keep --text behavior is met by the autnum-text golden case.

Full details: Out of Scope Changes check

Explanation

Changes are: a type check in RunCLI for --whois (cli.go); an autnum fixture route in fixtureServer and three AS64496 golden cases (cli_test.go); and three golden files. All of these serve #37. The fixture and golden tests support the new behavior and the text-mode regression check. The PR description discloses that --whois --json on non-domain queries now fails. This follows from the incompatible-output scope in #37, so it is not unrelated work. No unrelated changes were identified. The line-level cli.go diff could not be read, so this verdict depends on the summary.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 32db2e54-e706-45fa-83df-f2a09a278f99
Commits

Reviewing files that changed from the base of the PR and between 64c8c7d and 532ff06.

Files selected for processing: 5

  • cli.go
  • cli_test.go
  • testdata/cli/autnum-text.golden
  • testdata/cli/autnum-whois-json.golden
  • testdata/cli/autnum-whois.golden

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

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.

Non-domain queries combined with an incompatible output option like --whois emit no output but still return a zero exit code

1 participant