Skip to content

Conversation

@darkdragon-001
Copy link
Contributor

This makes error handling a lot easier.

I am not sure if it would be better to add a field to each Exception class with the preferred rcode, but this would require all exception modules to import rcode as well.

@nicki-krizek
Copy link
Collaborator

While I understand this might be useful for your specific application, it doesn't make sense to include this in a general dns handling package.

You really can't translate an exception into a return code in a way that isn't application specific. As one example for all, dns.exception.Timeout has no relation with SERVFAIL. The prior may be caused by network conditions and indicates a lack of response. The second means an actual return code in a dns response.

@darkdragon-001
Copy link
Contributor Author

darkdragon-001 commented Dec 31, 2025

While I understand this might be useful for your specific application, it doesn't make sense to include this in a general dns handling package.

You really can't translate an exception into a return code in a way that isn't application specific. As one example for all, dns.exception.Timeout has no relation with SERVFAIL. The prior may be caused by network conditions and indicates a lack of response. The second means an actual return code in a dns response.

My understanding is that SERVFAIL is the default error when no other code makes sense.

@nicki-krizek
Copy link
Collaborator

My understanding is that SERVFAIL is the default error when no other code makes sense.

That would be the case for a resolver deciding what return code to put into an answer for a client when the query fails to resolve.

But imagine dnspython is used as a client instead. You send a query and receive no answer over the network, aka dns.exception.Timeout. That is something different from sending a query and receiving a response from the server that has the return code set to SERVFAIL.

@darkdragon-001
Copy link
Contributor Author

That would be the case for a resolver deciding what return code to put into an answer for a client when the query fails to resolve.

But imagine dnspython is used as a client instead. You send a query and receive no answer over the network, aka dns.exception.Timeout. That is something different from sending a query and receiving a response from the server that has the return code set to SERVFAIL.

Yes, it would be a one-way mapping exception to rcode. This is why I created a from_exception() function but not a to_exception() one. Also it's a many-to-one mapping, so multiple exceptions can map to the same rcode, so the inverse operation is not well-defined anyways.

@rthalley
Copy link
Owner

I agree with Nicki's comments about the non-generality of this function. It also has incorrect mappings (e.g. BADSIG is a TSIG error; DNSSEC validation failures are usually SERVFAILs).

I am concerned that you are doing a bunch of work that is not going to be something I would merge.

@darkdragon-001
Copy link
Contributor Author

I agree with Nicki's comments about the non-generality of this function. It also has incorrect mappings (e.g. BADSIG is a TSIG error; DNSSEC validation failures are usually SERVFAILs).

Fixed.

I am concerned that you are doing a bunch of work that is not going to be something I would merge.

This is unfortunate as the Python DNS package ecosystem is already very fragmented (more than 3000 results for "dns" query on pypi.org).

Not merging it here leaves me with the options:

  1. Forking
  2. Contributing to another library
  3. Creating yet another independent library

@rthalley
Copy link
Owner

rthalley commented Jan 1, 2026

I still don't think there is a useful generalization of exception to rcode and so I will close this PR.

@rthalley rthalley closed this Jan 1, 2026
@darkdragon-001 darkdragon-001 deleted the error-codes branch January 2, 2026 11:54
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.

3 participants