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.
@@ -20,13 +20,14 @@ func DeviceConfig(d *device.Device) (*Config, error) {
w.Close()
}()
cfg, err := FromUAPI(r)
- if err != nil {
- return nil, err
+ // Prefer errors from IpcGetOperation.
+ if setErr := <-errc; setErr != nil {
+ return nil, setErr
}
- if err := <-errc; err != nil {
+ // Check FromUAPI error.
+ if err != nil {
return nil, err
}
-
sort.Slice(cfg.Peers, func(i, j int) bool {
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)
- if err != nil {
- return err
- }
w.Close()
- return <-errc
+ // Prefer errors from IpcSetOperation.
+ if setErr := <-errc; setErr != nil {
+ return setErr
+ }
+ return err // err (if any) from cfg.ToUAPI
}
