Skip to content

Provide dig exit code in CouldNotFetchDns exception - #124

Merged
freekmurze merged 6 commits into
mainfrom
provide-exit-code-in-could-not-fetch-dns
May 22, 2026
Merged

Provide dig exit code in CouldNotFetchDns exception#124
freekmurze merged 6 commits into
mainfrom
provide-exit-code-in-could-not-fetch-dns

Conversation

@freekmurze

@freekmurze freekmurze commented May 22, 2026

Copy link
Copy Markdown
Member

Why

Discussion #123 reports that when a dig lookup fails, the exception is hard to diagnose:

It makes it seem as if the message ;; IDN output support not enabled was the error, which sent me spiralling trying to debug that message. (...) The exception was thrown because an unsuccessful exit code was returned by dig, but that exit code is not provided in the exception.

CouldNotFetchDns::digReturnedWithError() built its message straight from dig's stderr. dig writes ;; IDN output support not enabled to stderr regardless of success, so when a lookup also failed (typically a transient "no reply from server"), that unrelated warning surfaced as the error message and the real signal, the non-zero exit code, was dropped entirely.

What changed

  • The exit code now leads the message and is mapped to dig's documented meaning where known.
  • The exit code is exposed via a public ?int $exitCode property so callers can branch on it programmatically.
  • dig's stderr is kept as supplementary context rather than masquerading as the cause. The ;; IDN output support not enabled warning can be genuinely useful for internationalized domains, so it is demoted, not discarded.

Message, before and after

Before:

Dig command `...` failed with message: `;; IDN output support not enabled`

After:

Dig command `...` failed with exit code 9 (no reply from server): `;; IDN output support not enabled`
catch (CouldNotFetchDns $exception) {
    $exception->exitCode; // 9
}

The $exitCode is null for the non-dig paths (noHandlerFound, dnsGetRecordReturnedWithError).

freekmurze and others added 6 commits May 22, 2026 11:15
When a dig lookup fails, the exception message used to be built straight
from dig's stderr. dig writes the warning `;; IDN output support not
enabled` to stderr, so that warning surfaced as the error message while
the actual failure signal (the non-zero exit code) was dropped entirely.
As reported in discussion #123, this made failures very hard to diagnose.

The exit code now leads the message, is mapped to dig's documented
meaning where known, and is exposed via a readonly `$exitCode` property
for programmatic inspection. dig's stderr is kept as supplementary
context rather than masquerading as the cause.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Replace the lookup constant with a dedicated method using a match
expression.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Replaces the PHP CS Fixer workflow with Pint, using actions that run on
Node 24 (checkout@v6, laravel-pint-action@2.6, git-auto-commit@v7),
resolving the Node 20 deprecation warning on the styling workflow.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@freekmurze
freekmurze merged commit 567e01f into main May 22, 2026
17 checks passed
@freekmurze
freekmurze deleted the provide-exit-code-in-could-not-fetch-dns branch May 22, 2026 09:38
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.

1 participant