feat(cli): Add dig compatible error exit code 9

This patch implements the error exit code for "No reply from server"
that dig uses to indicate that it was unable to resolve an address due
to the inability to reach any resolver.

References:
https://linux.die.net/man/1/dig
pull/57/head
Sheogorath 2022-10-18 16:24:24 +02:00 committed by Karan Sharma
parent 0da9178683
commit 9386c589bf
1 changed files with 10 additions and 1 deletions

View File

@ -148,16 +148,25 @@ func main() {
}
// Resolve Queries.
var responses []resolvers.Response
var (
responses []resolvers.Response
responseErrors []error
)
for _, q := range app.Questions {
for _, rslv := range app.Resolvers {
resp, err := rslv.Lookup(q)
if err != nil {
app.Logger.WithError(err).Error("error looking up DNS records")
responseErrors = append(responseErrors, err)
}
responses = append(responses, resp)
}
}
if len(responses) == 0 && len(responseErrors) > 0 {
app.Logger.Exit(9)
}
app.Output(responses)
// Quitting.