From 232b207d8da42dad297f2730c42e5e84f9049ab9 Mon Sep 17 00:00:00 2001 From: Dimitry Kolyshev Date: Thu, 13 Jun 2024 12:18:41 +0300 Subject: [PATCH] all: rm aghos unsupported err --- internal/aghos/os.go | 20 ++------------------ internal/dnsforward/ipset.go | 3 +-- internal/home/home.go | 2 +- internal/ipset/ipset.go | 4 ++-- 4 files changed, 6 insertions(+), 23 deletions(-) diff --git a/internal/aghos/os.go b/internal/aghos/os.go index e04055e4..f2933a98 100644 --- a/internal/aghos/os.go +++ b/internal/aghos/os.go @@ -19,25 +19,9 @@ import ( "github.com/AdguardTeam/golibs/log" ) -// UnsupportedError is returned by functions and methods when a particular -// operation Op cannot be performed on the current OS. -type UnsupportedError struct { - Op string - OS string -} - -// Error implements the error interface for *UnsupportedError. -func (err *UnsupportedError) Error() (msg string) { - return fmt.Sprintf("%s is unsupported on %s", err.Op, err.OS) -} - -// Unsupported is a helper that returns an *UnsupportedError with the Op field -// set to op and the OS field set to the current OS. +// Unsupported is a helper that returns a wrapped [errors.ErrUnsupported]. func Unsupported(op string) (err error) { - return &UnsupportedError{ - Op: op, - OS: runtime.GOOS, - } + return fmt.Errorf("%s: not supported on %s: %w", op, runtime.GOOS, errors.ErrUnsupported) } // SetRlimit sets user-specified limit of how many fd's we can use. diff --git a/internal/dnsforward/ipset.go b/internal/dnsforward/ipset.go index cb6b1663..cd841c34 100644 --- a/internal/dnsforward/ipset.go +++ b/internal/dnsforward/ipset.go @@ -6,7 +6,6 @@ import ( "os" "strings" - "github.com/AdguardTeam/AdGuardHome/internal/aghos" "github.com/AdguardTeam/AdGuardHome/internal/ipset" "github.com/AdguardTeam/golibs/errors" "github.com/AdguardTeam/golibs/log" @@ -35,7 +34,7 @@ func (c *ipsetCtx) init(ipsetConf []string) (err error) { log.Info("ipset: warning: cannot initialize: %s", err) return nil - } else if unsupErr := (&aghos.UnsupportedError{}); errors.As(err, &unsupErr) { + } else if errors.Is(err, errors.ErrUnsupported) { log.Info("ipset: warning: %s", err) return nil diff --git a/internal/home/home.go b/internal/home/home.go index f7db7da0..93e8e09d 100644 --- a/internal/home/home.go +++ b/internal/home/home.go @@ -178,7 +178,7 @@ func setupContext(opts options) (err error) { // unsupported errors and returns nil. If err is nil, logIfUnsupported returns // nil. Otherwise, it returns err. func logIfUnsupported(msg string, err error) (outErr error) { - if errors.As(err, new(*aghos.UnsupportedError)) { + if errors.Is(err, errors.ErrUnsupported) { log.Debug(msg, err) return nil diff --git a/internal/ipset/ipset.go b/internal/ipset/ipset.go index a81102a1..6e68662d 100644 --- a/internal/ipset/ipset.go +++ b/internal/ipset/ipset.go @@ -22,8 +22,8 @@ type Manager interface { // // DOMAIN[,DOMAIN].../IPSET_NAME[,IPSET_NAME]... // -// If ipsetConf is empty, msg and err are nil. The error is of type -// *aghos.UnsupportedError if the OS is not supported. +// If ipsetConf is empty, msg and err are nil. The error's chain contains +// [errors.UnsupportedError] if current OS is not supported. func NewManager(ipsetConf []string) (mgr Manager, err error) { if len(ipsetConf) == 0 { return nil, nil