Skip to content

Commit

Permalink
feat(exchanger): add request question context when encountering an error
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Nov 3, 2024
1 parent b2cf2c0 commit 5326983
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions internal/exchanger/exchanger.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ func (e *Exchanger) Exchange(ctx context.Context, network string, request *dns.M
) {
netConn, err := e.dialer.Dial(ctx, network, "")
if err != nil {
return nil, fmt.Errorf("dialing %s server: %w", e.dialer, err)
return nil, fmt.Errorf("dialing %s server for request %s: %w",
e.dialer, extractRequestQuestion(request), err)
}
dnsConn := &dns.Conn{Conn: netConn}

Expand All @@ -38,8 +39,19 @@ func (e *Exchanger) Exchange(ctx context.Context, network string, request *dns.M
}

if err != nil {
return nil, fmt.Errorf("exchanging over %s connection: %w", e.dialer, err)
return nil, fmt.Errorf("exchanging over %s connection for request %s: %w",
e.dialer, extractRequestQuestion(request), err)
}

return response, nil
}

func extractRequestQuestion(request *dns.Msg) (s string) {
if len(request.Question) == 0 {
return "<no question>"
}
question := request.Question[0]
return dns.ClassToString[question.Qclass] + " " +
dns.TypeToString[question.Qtype] + " " +
question.Name
}

0 comments on commit 5326983

Please sign in to comment.