1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00

Switch to Go 1.13 error wrapping (#604)

* Replaced errors.Wrap with fmt.Errorf (#589)

* Find:    errors\.Wrap\(([^,]+),\s+(["`][^"`]*)(["`])\)
  Replace: fmt.Errorf($2: %w$3, $1)

* Replaced errors.Wrapf with fmt.Errorf (#589)

* Find:    errors\.Wrapf\(([^,]+),\s+(["`][^"`]*)(["`])\)
  Replace: fmt.Errorf($2: %w$3, $1)
* Find:    errors\.Wrapf\(([^,]+),\s+(["`][^"`]*)(["`])(,[^)]+)\)
* Replace: fmt.Errorf($2: %w$3$4, $1)

* Replaced errors.Errorf with fmt.Errorf (#589)

* Find:    errors\.Errorf
  Replace: fmt.Errorf

* Cleaned up remaining imports

* Cleanup

* Regenerate provider support matrix

This was broken by #533 ... and it's now the third time this has been missed.
This commit is contained in:
Patrick Gaskin
2020-01-28 11:06:56 -05:00
committed by Tom Limoncelli
parent cae35a2c8f
commit 825ba2d081
64 changed files with 328 additions and 379 deletions

View File

@ -1,9 +1,8 @@
package models
import (
"fmt"
"net"
"github.com/pkg/errors"
)
// PopulateFromString populates a RecordConfig given a type and string.
@ -15,23 +14,23 @@ import (
// misunderstood data. We do this panic() at the provider level.
// Therefore the typical calling sequence is:
// if err := rc.PopulateFromString(rtype, value, origin); err != nil {
// panic(errors.Wrap(err, "unparsable record received from provider"))
// panic(fmt.Errorf("unparsable record received from provider: %w", err))
// }
func (r *RecordConfig) PopulateFromString(rtype, contents, origin string) error {
if r.Type != "" && r.Type != rtype {
panic(errors.Errorf("assertion failed: rtype already set (%s) (%s)", rtype, r.Type))
panic(fmt.Errorf("assertion failed: rtype already set (%s) (%s)", rtype, r.Type))
}
switch r.Type = rtype; rtype { // #rtype_variations
case "A":
ip := net.ParseIP(contents)
if ip == nil || ip.To4() == nil {
return errors.Errorf("A record with invalid IP: %s", contents)
return fmt.Errorf("A record with invalid IP: %s", contents)
}
return r.SetTargetIP(ip) // Reformat to canonical form.
case "AAAA":
ip := net.ParseIP(contents)
if ip == nil || ip.To16() == nil {
return errors.Errorf("AAAA record with invalid IP: %s", contents)
return fmt.Errorf("AAAA record with invalid IP: %s", contents)
}
return r.SetTargetIP(ip) // Reformat to canonical form.
case "ANAME", "CNAME", "NS", "PTR":
@ -51,7 +50,7 @@ func (r *RecordConfig) PopulateFromString(rtype, contents, origin string) error
case "TXT":
return r.SetTargetTXTString(contents)
default:
return errors.Errorf("Unknown rtype (%s) when parsing (%s) domain=(%s)",
return fmt.Errorf("Unknown rtype (%s) when parsing (%s) domain=(%s)",
rtype, contents, origin)
}
}