leaf icon indicating copy to clipboard operation
leaf copied to clipboard

refactor: flatten nested match and improve readability in DNS lookup loop

Open sage417 opened this issue 2 months ago • 0 comments

Refactor the DNS lookup retry loop to reduce deeply nested match statements and improve code clarity and maintainability.

The original implementation had multiple levels of nested match blocks for handling send, receive, timeout, and DNS response parsing, which made the logic hard to follow and error-prone.

This refactoring:

  • Replaces deep nesting with early returns and if let bindings where appropriate.
  • Keeps the existing error classification logic (e.g., which errors are retried like timeouts or send failures, and which are fatal like parse errors or invalid DNS responses).
  • Improves readability by organizing the steps sequentially: send → receive (with timeout) → parse → validate → extract IPs → build result.
  • Maintains all existing behavior including retry logic and error handling.
  • Adds clarity around TTL extraction and deadline calculation.

No functional changes — only structural and readability improvements.

sage417 avatar Nov 11 '25 07:11 sage417