Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Switch from fmt.Error* to errors.Error* #317

Merged
merged 1 commit into from
Feb 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions build/validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strings"

"github.com/google/go-github/github"
"github.com/pkg/errors"

"golang.org/x/oauth2"
)
Expand Down Expand Up @@ -59,7 +60,7 @@ func checkGoFmt() error {
if fList == "" {
return nil
}
return fmt.Errorf("The following files need to have gofmt run on them:\n%s", fList)
return errors.Errorf("The following files need to have gofmt run on them:\n%s", fList)
}

func checkGoGenerate() error {
Expand All @@ -75,7 +76,7 @@ func checkGoGenerate() error {
return err
}
if len(modified) != 0 {
return fmt.Errorf("ERROR: The following files are modified after go generate:\n%s", strings.Join(modified, "\n"))
return errors.Errorf("ERROR: The following files are modified after go generate:\n%s", strings.Join(modified, "\n"))
}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/convertzone/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func parseargs(args []string) (zonename string, filename string, r io.Reader, er
// Anything else returns an error.

if len(args) < 2 {
return "", "", nil, fmt.Errorf("no command line parameters. Zone name required")
return "", "", nil, errors.Errorf("no command line parameters. Zone name required")
}

zonename = args[0]
Expand All @@ -56,7 +56,7 @@ func parseargs(args []string) (zonename string, filename string, r io.Reader, er
return "", "", nil, errors.Wrapf(err, "Could not open file: %s", filename)
}
} else {
return "", "", nil, fmt.Errorf("too many command line parameters")
return "", "", nil, errors.Errorf("too many command line parameters")
}

return zonename, filename, r, nil
Expand Down
5 changes: 3 additions & 2 deletions commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"

"github.com/StackExchange/dnscontrol/models"
"github.com/pkg/errors"
"github.com/urfave/cli"
)

Expand Down Expand Up @@ -116,7 +117,7 @@ func preloadProviders(cfg *models.DNSConfig, err error) (*models.DNSConfig, erro
for _, d := range cfg.Domains {
reg, ok := cfg.RegistrarsByName[d.RegistrarName]
if !ok {
return nil, fmt.Errorf("Registrar named %s expected for %s, but never registered", d.RegistrarName, d.Name)
return nil, errors.Errorf("Registrar named %s expected for %s, but never registered", d.RegistrarName, d.Name)
}
d.RegistrarInstance = &models.RegistrarInstance{
ProviderBase: models.ProviderBase{
Expand All @@ -127,7 +128,7 @@ func preloadProviders(cfg *models.DNSConfig, err error) (*models.DNSConfig, erro
for pName, n := range d.DNSProviderNames {
prov, ok := cfg.DNSProvidersByName[pName]
if !ok {
return nil, fmt.Errorf("DNS Provider named %s expected for %s, but never registered", pName, d.Name)
return nil, errors.Errorf("DNS Provider named %s expected for %s, but never registered", pName, d.Name)
}
d.DNSProviderInstances = append(d.DNSProviderInstances, &models.DNSProviderInstance{
ProviderBase: models.ProviderBase{
Expand Down
5 changes: 3 additions & 2 deletions commands/previewPush.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/StackExchange/dnscontrol/pkg/printer"
"github.com/StackExchange/dnscontrol/providers"
"github.com/StackExchange/dnscontrol/providers/config"
"github.com/pkg/errors"
"github.com/urfave/cli"
)

Expand Down Expand Up @@ -94,7 +95,7 @@ func run(args PreviewArgs, push bool, interactive bool, out printer.CLI) error {
}
errs := normalize.NormalizeAndValidateConfig(cfg)
if PrintValidationErrors(errs) {
return fmt.Errorf("Exiting due to validation errors")
return errors.Errorf("Exiting due to validation errors")
}
// TODO:
notifier, err := InitializeProviders(args.CredsFile, cfg, args.Notify)
Expand Down Expand Up @@ -162,7 +163,7 @@ DomainLoop:
notifier.Done()
out.Debugf("Done. %d corrections.\n", totalCorrections)
if anyErrors {
return fmt.Errorf("Completed with errors")
return errors.Errorf("Completed with errors")
}
return nil
}
Expand Down
9 changes: 5 additions & 4 deletions commands/printIR.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/StackExchange/dnscontrol/models"
"github.com/StackExchange/dnscontrol/pkg/js"
"github.com/StackExchange/dnscontrol/pkg/normalize"
"github.com/pkg/errors"
"github.com/urfave/cli"
)

Expand Down Expand Up @@ -72,7 +73,7 @@ func PrintIR(args PrintIRArgs) error {
if !args.Raw {
errs := normalize.NormalizeAndValidateConfig(cfg)
if PrintValidationErrors(errs) {
return fmt.Errorf("Exiting due to validation errors")
return errors.Errorf("Exiting due to validation errors")
}
}
return PrintJSON(args.PrintJSONArgs, cfg)
Expand All @@ -98,15 +99,15 @@ func PrintValidationErrors(errs []error) (fatal bool) {
// ExecuteDSL executes the dnsconfig.js contents.
func ExecuteDSL(args ExecuteDSLArgs) (*models.DNSConfig, error) {
if args.JSFile == "" {
return nil, fmt.Errorf("No config specified")
return nil, errors.Errorf("No config specified")
}
text, err := ioutil.ReadFile(args.JSFile)
if err != nil {
return nil, fmt.Errorf("Reading js file %s: %s", args.JSFile, err)
return nil, errors.Errorf("Reading js file %s: %s", args.JSFile, err)
}
dnsConfig, err := js.ExecuteJavascript(string(text), args.DevMode)
if err != nil {
return nil, fmt.Errorf("Executing javascript in %s: %s", args.JSFile, err)
return nil, errors.Errorf("Executing javascript in %s: %s", args.JSFile, err)
}
return dnsConfig, nil
}
Expand Down
19 changes: 10 additions & 9 deletions models/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/StackExchange/dnscontrol/pkg/transform"
"github.com/miekg/dns"
"github.com/pkg/errors"
"golang.org/x/net/idna"
)

Expand Down Expand Up @@ -452,12 +453,12 @@ func SplitCombinedMxValue(s string) (preference uint16, target string, err error
parts := strings.Fields(s)

if len(parts) != 2 {
return 0, "", fmt.Errorf("MX value %#v contains too many fields", s)
return 0, "", errors.Errorf("MX value %#v contains too many fields", s)
}

n64, err := strconv.ParseUint(parts[0], 10, 16)
if err != nil {
return 0, "", fmt.Errorf("MX preference %#v does not fit into a uint16", parts[0])
return 0, "", errors.Errorf("MX preference %#v does not fit into a uint16", parts[0])
}
return uint16(n64), parts[1], nil
}
Expand All @@ -484,20 +485,20 @@ func SplitCombinedSrvValue(s string) (priority, weight, port uint16, target stri
parts := strings.Fields(s)

if len(parts) != 4 {
return 0, 0, 0, "", fmt.Errorf("SRV value %#v contains too many fields", s)
return 0, 0, 0, "", errors.Errorf("SRV value %#v contains too many fields", s)
}

priorityconv, err := strconv.ParseInt(parts[0], 10, 16)
if err != nil {
return 0, 0, 0, "", fmt.Errorf("Priority %#v does not fit into a uint16", parts[0])
return 0, 0, 0, "", errors.Errorf("Priority %#v does not fit into a uint16", parts[0])
}
weightconv, err := strconv.ParseInt(parts[1], 10, 16)
if err != nil {
return 0, 0, 0, "", fmt.Errorf("Weight %#v does not fit into a uint16", parts[0])
return 0, 0, 0, "", errors.Errorf("Weight %#v does not fit into a uint16", parts[0])
}
portconv, err := strconv.ParseInt(parts[2], 10, 16)
if err != nil {
return 0, 0, 0, "", fmt.Errorf("Port %#v does not fit into a uint16", parts[0])
return 0, 0, 0, "", errors.Errorf("Port %#v does not fit into a uint16", parts[0])
}
return uint16(priorityconv), uint16(weightconv), uint16(portconv), parts[3], nil
}
Expand All @@ -522,7 +523,7 @@ func SplitCombinedCaaValue(s string) (tag string, flag uint8, value string, err

splitData := strings.SplitN(s, " ", 3)
if len(splitData) != 3 {
err = fmt.Errorf("Unexpected data for CAA record returned by Vultr")
err = errors.Errorf("Unexpected data for CAA record returned by Vultr")
return
}

Expand Down Expand Up @@ -588,9 +589,9 @@ func InterfaceToIP(i interface{}) (net.IP, error) {
if ip := net.ParseIP(v); ip != nil {
return ip, nil
}
return nil, fmt.Errorf("%s is not a valid ip address", v)
return nil, errors.Errorf("%s is not a valid ip address", v)
default:
return nil, fmt.Errorf("cannot convert type %s to ip", reflect.TypeOf(i))
return nil, errors.Errorf("cannot convert type %s to ip", reflect.TypeOf(i))
}
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/normalize/flatten.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package normalize

import (
"fmt"
"strings"

"github.com/miekg/dns/dnsutil"
"github.com/pkg/errors"

"github.com/StackExchange/dnscontrol/models"
"github.com/StackExchange/dnscontrol/pkg/spflib"
Expand Down Expand Up @@ -40,7 +40,7 @@ func flattenSPFs(cfg *models.DNSConfig) []error {
// now split if needed
if split, ok := txt.Metadata["split"]; ok {
if !strings.Contains(split, "%d") {
errs = append(errs, Warning{fmt.Errorf("Split format `%s` in `%s` is not proper format (should have %%d in it)", split, txt.NameFQDN)})
errs = append(errs, Warning{errors.Errorf("Split format `%s` in `%s` is not proper format (should have %%d in it)", split, txt.NameFQDN)})
continue
}
recs := rec.TXTSplit(split + "." + domain.Name)
Expand All @@ -63,15 +63,15 @@ func flattenSPFs(cfg *models.DNSConfig) []error {
}
// check if cache is stale
for _, e := range cache.ResolveErrors() {
errs = append(errs, Warning{fmt.Errorf("problem resolving SPF record: %s", e)})
errs = append(errs, Warning{errors.Errorf("problem resolving SPF record: %s", e)})
}
if len(cache.ResolveErrors()) == 0 {
changed := cache.ChangedRecords()
if len(changed) > 0 {
if err := cache.Save("spfcache.updated.json"); err != nil {
errs = append(errs, err)
} else {
errs = append(errs, Warning{fmt.Errorf("%d spf record lookups are out of date with cache (%s).\nWrote changes to spfcache.updated.json. Please rename and commit:\n $ mv spfcache.updated.json spfcache.json\n $ git commit spfcache.json", len(changed), strings.Join(changed, ","))})
errs = append(errs, Warning{errors.Errorf("%d spf record lookups are out of date with cache (%s).\nWrote changes to spfcache.updated.json. Please rename and commit:\n $ mv spfcache.updated.json spfcache.json\n $ git commit spfcache.json", len(changed), strings.Join(changed, ","))})
}
}
}
Expand Down
Loading