Spruce up errors a bit
This commit is contained in:
parent
32cc38ab08
commit
6c8d37a054
@ -378,7 +378,7 @@ func (d *Daemon) SetConfig(
|
||||
d,
|
||||
func(ctx context.Context, n joinedNetwork) (struct{}, error) {
|
||||
if n.config != nil {
|
||||
return struct{}{}, ErrUserManagedNetworkConfig
|
||||
return struct{}{}, ErrManagedNetworkConfig
|
||||
}
|
||||
|
||||
// TODO needs to check that public addresses aren't being shared
|
||||
|
@ -202,7 +202,7 @@ func TestDaemon_SetConfig(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("ErrUserManagedNetworkConfig", func(t *testing.T) {
|
||||
t.Run("ErrManagedNetworkConfig", func(t *testing.T) {
|
||||
var (
|
||||
creationParams = bootstrap.NewCreationParams("AAA", "a.com")
|
||||
networkA = network.NewMockNetwork(t)
|
||||
@ -222,6 +222,6 @@ func TestDaemon_SetConfig(t *testing.T) {
|
||||
|
||||
networkConfig.VPN.Tun.Device = "foo"
|
||||
err := h.daemon.SetConfig(h.ctx, networkConfig)
|
||||
assert.ErrorIs(t, err, ErrUserManagedNetworkConfig)
|
||||
assert.ErrorIs(t, err, ErrManagedNetworkConfig)
|
||||
})
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ const (
|
||||
errCodeAlreadyJoined
|
||||
errCodeNoMatchingNetworks
|
||||
errCodeMultipleMatchingNetworks
|
||||
errCodeUserManagedNetworkConfig
|
||||
errCodeManagedNetworkConfig
|
||||
)
|
||||
|
||||
var (
|
||||
@ -35,10 +35,10 @@ var (
|
||||
"Multiple networks matched the search string",
|
||||
)
|
||||
|
||||
// ErrUserManagedNetworkConfig is returned when attempting to modify a
|
||||
// ErrManagedNetworkConfig is returned when attempting to modify a
|
||||
// network config which is managed by the user.
|
||||
ErrUserManagedNetworkConfig = jsonrpc2.NewError(
|
||||
errCodeUserManagedNetworkConfig,
|
||||
"Network configuration is managed by the user",
|
||||
ErrManagedNetworkConfig = jsonrpc2.NewError(
|
||||
errCodeManagedNetworkConfig,
|
||||
"Network configuration is managed by the daemon.yml",
|
||||
)
|
||||
)
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@ -75,7 +76,9 @@ func (c *httpClient) Call(
|
||||
dec := json.NewDecoder(res.Body)
|
||||
|
||||
resID, err := decodeResponse(dec, rcv)
|
||||
if err != nil {
|
||||
if errors.As(err, new(Error)) {
|
||||
return err
|
||||
} else if err != nil {
|
||||
return fmt.Errorf("decoding response: %w", err)
|
||||
} else if resID != id {
|
||||
return fmt.Errorf(
|
||||
|
@ -3,6 +3,7 @@ package jsonrpc2
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
@ -27,7 +28,9 @@ func (c rwClient) Call(
|
||||
}
|
||||
|
||||
resID, err := decodeResponse(c.dec, rcv)
|
||||
if err != nil {
|
||||
if errors.As(err, new(Error)) {
|
||||
return err
|
||||
} else if err != nil {
|
||||
return fmt.Errorf("decoding response: %w", err)
|
||||
} else if resID != id {
|
||||
return fmt.Errorf(
|
||||
|
@ -29,7 +29,7 @@ type RPC interface {
|
||||
GetNetworks(context.Context) ([]bootstrap.CreationParams, error)
|
||||
|
||||
// SetConfig extends the [network.RPC] method of the same name such that
|
||||
// [ErrUserManagedNetworkConfig] is returned if the picked network is
|
||||
// [ErrManagedNetworkConfig] is returned if the picked network is
|
||||
// configured as part of the [daecommon.Config] which the Daemon was
|
||||
// initialized with.
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user