Skip to content

Commit

Permalink
device: return generic error from Ipc{Get,Set}Operation.
Browse files Browse the repository at this point in the history
This makes uapi.go's public API conform to Go style in terms
of error types.

Signed-off-by: David Anderson <danderson@tailscale.com>
  • Loading branch information
danderson committed Apr 1, 2020
1 parent e852f4c commit 65f1869
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions device/uapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package device

import (
"bufio"
"errors"
"fmt"
"io"
"net"
Expand All @@ -31,7 +32,7 @@ func (s IPCError) ErrorCode() int64 {
return s.int64
}

func (device *Device) IpcGetOperation(socket *bufio.Writer) *IPCError {
func (device *Device) IpcGetOperation(socket *bufio.Writer) error {
lines := make([]string, 0, 100)
send := func(line string) {
lines = append(lines, line)
Expand Down Expand Up @@ -106,7 +107,7 @@ func (device *Device) IpcGetOperation(socket *bufio.Writer) *IPCError {
return nil
}

func (device *Device) IpcSetOperation(socket *bufio.Reader) *IPCError {
func (device *Device) IpcSetOperation(socket *bufio.Reader) error {
scanner := bufio.NewScanner(socket)
logError := device.log.Error
logDebug := device.log.Debug
Expand Down Expand Up @@ -421,10 +422,20 @@ func (device *Device) IpcHandle(socket net.Conn) {

switch op {
case "set=1\n":
status = device.IpcSetOperation(buffered.Reader)
err = device.IpcSetOperation(buffered.Reader)
if !errors.As(err, &status) {
// should never happen
device.log.Error.Println("Invalid UAPI error:", err)
status = &IPCError{1}
}

case "get=1\n":
status = device.IpcGetOperation(buffered.Writer)
err = device.IpcGetOperation(buffered.Writer)
if !errors.As(err, &status) {
// should never happen
device.log.Error.Println("Invalid UAPI error:", err)
status = &IPCError{1}
}

default:
device.log.Error.Println("Invalid UAPI operation:", op)
Expand Down

0 comments on commit 65f1869

Please sign in to comment.