Skip to content

Commit

Permalink
Pull request: AG-33410-aghos-err
Browse files Browse the repository at this point in the history
Merge in DNS/adguard-home from AG-33410-aghos-err to master

Squashed commit of the following:

commit 6014ea1
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Fri Jun 14 08:30:30 2024 +0300

    all: imp code

commit 232b207
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Thu Jun 13 12:18:41 2024 +0300

    all: rm aghos unsupported err
  • Loading branch information
Mizzick committed Jun 14, 2024
1 parent bed86d5 commit 8432593
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 23 deletions.
20 changes: 2 additions & 18 deletions internal/aghos/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions internal/dnsforward/ipset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/home/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions internal/ipset/ipset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.ErrUnsupported] if current OS is not supported.
func NewManager(ipsetConf []string) (mgr Manager, err error) {
if len(ipsetConf) == 0 {
return nil, nil
Expand Down

0 comments on commit 8432593

Please sign in to comment.