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