Skip to content

fix: filter JSON/raw output by record type (#986)#988

Merged
Mzack9999 merged 1 commit into
devfrom
fix/986-json-record-type-filter
Jun 2, 2026
Merged

fix: filter JSON/raw output by record type (#986)#988
Mzack9999 merged 1 commit into
devfrom
fix/986-json-record-type-filter

Conversation

@dogancanbakir

@dogancanbakir dogancanbakir commented Jun 1, 2026

Copy link
Copy Markdown
Member

Closes #986.

JSON/raw output emitted every resolved host regardless of the requested record type, unlike text output. Now filtered to hosts with a matching record. Default, -all and AXFR are untouched.

Note: -cname etc. now also filter JSON/raw output, not just query. Tightly scoped to explicit selectors so existing -j full-dump pipelines are unaffected.

Summary by CodeRabbit

  • New Features
    • When explicitly selecting specific DNS record types, JSON and raw output formats now filter results to display only matching records.

@dogancanbakir dogancanbakir self-assigned this Jun 1, 2026
@dogancanbakir dogancanbakir requested a review from Mzack9999 June 1, 2026 11:03
@coderabbitai

coderabbitai Bot commented Jun 1, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: fc5c2d42-d3fe-4733-8471-0d85a8097c49

📥 Commits

Reviewing files that changed from the base of the PR and between 13dbf81 and 74ab495.

📒 Files selected for processing (3)
  • internal/runner/options.go
  • internal/runner/runner.go
  • internal/runner/runner_test.go

Walkthrough

The PR fixes output filtering for explicit DNS record-type selectors in JSON and raw output modes. Three changes work together: a new Options field tracks explicit type selection, a helper validates whether responses contain selected record types, and the worker loop uses that helper to skip output for non-matching responses.

Changes

DNS Record-Type Output Filtering

Layer / File(s) Summary
Options tracking for explicit record types
internal/runner/options.go, internal/runner/runner.go
Adds explicitRecordTypes boolean field to Options struct. Flag is set in New() when users explicitly select any DNS question types.
Record selection validation and testing
internal/runner/runner.go, internal/runner/runner_test.go
Introduces hasSelectedRecord(*dnsx.ResponseData) bool helper that checks if a response contains records for selected types (A/AAAA/CNAME/NS/TXT/SRV/PTR/MX/SOA/CAA) or ANY. Test imports add dnsx and retryabledns dependencies. Table-driven TestHasSelectedRecord validates helper behavior across CNAME, A, ANY, and multi-type selections with CNAME-only, A-only, and empty response fixtures.
Worker output filtering
internal/runner/runner.go
Worker loop adds early continue for JSON/raw output: when record-type selectors are explicitly set (excluding QueryAll and AXFR), output is skipped entirely if response contains no matching record types.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A filter so keen, with flags running clean,
When JSON flows forth, now only what's seen—
CNAME, A, or ANY, the record types shine,
No more empty echoes, just matches divine!
The rabbit approves of this filtering line! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: filtering JSON/raw output by record type when explicit selectors are provided.
Linked Issues check ✅ Passed The PR implements filtering of JSON/raw output to match the record-type selector logic, directly addressing issue #986's requirement that -cname -j -omit-raw should output only domains with CNAME records.
Out of Scope Changes check ✅ Passed All changes are scoped to the record-type filtering feature: adding the explicitRecordTypes field, implementing filter logic, and adding test coverage. No unrelated changes detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/986-json-record-type-filter

Comment @coderabbitai help to get the list of available commands and usage tips.

@Mzack9999 Mzack9999 merged commit e9607a3 into dev Jun 2, 2026
12 checks passed
@Mzack9999 Mzack9999 deleted the fix/986-json-record-type-filter branch June 2, 2026 21:24
@Mzack9999 Mzack9999 added the Type: Bug Inconsistencies or issues which will cause an issue or problem for users or implementors. label Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Bug Inconsistencies or issues which will cause an issue or problem for users or implementors.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

-cname -j -omit-raw is not working

2 participants