Skip to content

Commit

Permalink
feat(cli): Add dig compatible error exit code 9
Browse files Browse the repository at this point in the history
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
  • Loading branch information
SISheogorath authored and mr-karan committed Oct 19, 2022
1 parent 0da9178 commit 9386c58
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion cmd/doggo/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 9386c58

Please sign in to comment.