wgengine/wgcfg: return better errors from DeviceConfig, ReconfigDevice

Prefer the error from the actual wireguard-go device method call,
not {To,From}UAPI, as those tend to be less interesting I/O errors.

Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
pull/1874/head
Josh Bleecher Snyder 4 years ago
parent 1f6c4ba7c3
commit 777c816b34

@ -20,13 +20,14 @@ func DeviceConfig(d *device.Device) (*Config, error) {
w.Close() w.Close()
}() }()
cfg, err := FromUAPI(r) cfg, err := FromUAPI(r)
if err != nil { // Prefer errors from IpcGetOperation.
return nil, err if setErr := <-errc; setErr != nil {
return nil, setErr
} }
if err := <-errc; err != nil { // Check FromUAPI error.
if err != nil {
return nil, err return nil, err
} }
sort.Slice(cfg.Peers, func(i, j int) bool { sort.Slice(cfg.Peers, func(i, j int) bool {
return cfg.Peers[i].PublicKey.LessThan(&cfg.Peers[j].PublicKey) return cfg.Peers[i].PublicKey.LessThan(&cfg.Peers[j].PublicKey)
}) })
@ -54,9 +55,10 @@ func ReconfigDevice(d *device.Device, cfg *Config, logf logger.Logf) (err error)
}() }()
err = cfg.ToUAPI(w, prev) err = cfg.ToUAPI(w, prev)
if err != nil {
return err
}
w.Close() w.Close()
return <-errc // Prefer errors from IpcSetOperation.
if setErr := <-errc; setErr != nil {
return setErr
}
return err // err (if any) from cfg.ToUAPI
} }

Loading…
Cancel
Save