summaryrefslogtreecommitdiffhomepage
path: root/device
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josh@tailscale.com>2021-01-25 08:55:08 -0800
committerJosh Bleecher Snyder <josh@tailscale.com>2021-01-25 09:09:24 -0800
commit37a239e7360dd38e513fd7d717ce50de6d8215ff (patch)
treef11553aaa56eb60f181be32e54f7268388059959 /device
parent6252de0db9331cbc20074e9d40165266b5816148 (diff)
device: simplify IpcHandle error handling
Unify the handling of unexpected UAPI errors. The comment that says "should never happen" is incorrect; this could happen due to I/O errors. Correct it. Change error message capitalization for consistency. Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
Diffstat (limited to 'device')
-rw-r--r--device/uapi.go21
1 files changed, 6 insertions, 15 deletions
diff --git a/device/uapi.go b/device/uapi.go
index 7d180bb..160806d 100644
--- a/device/uapi.go
+++ b/device/uapi.go
@@ -411,31 +411,22 @@ func (device *Device) IpcHandle(socket net.Conn) {
}
// handle operation
-
- var status *IPCError
-
switch op {
case "set=1\n":
err = device.IpcSetOperation(buffered.Reader)
- if err != nil && !errors.As(err, &status) {
- // should never happen
- status = ipcErrorf(1, "invalid UAPI error: %w", err)
- }
-
case "get=1\n":
err = device.IpcGetOperation(buffered.Writer)
- if err != nil && !errors.As(err, &status) {
- // should never happen
- status = ipcErrorf(1, "invalid UAPI error: %w", err)
- }
-
default:
- device.log.Error.Println("Invalid UAPI operation:", op)
+ device.log.Error.Println("invalid UAPI operation:", op)
return
}
// write status
-
+ var status *IPCError
+ if err != nil && !errors.As(err, &status) {
+ // I/O error, maybe something unexpected
+ status = ipcErrorf(1, "other UAPI error: %w", err)
+ }
if status != nil {
device.log.Error.Println(status)
fmt.Fprintf(buffered, "errno=%d\n\n", status.ErrorCode())