device: return generic error from Ipc{Get,Set}Operation.
This makes uapi.go's public API conform to Go style in terms of error types. Signed-off-by: David Anderson <danderson@tailscale.com>
This commit is contained in:
parent
c76b818466
commit
f2c6faad44
@ -7,6 +7,7 @@ package device
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
@ -31,7 +32,7 @@ func (s IPCError) ErrorCode() int64 {
|
|||||||
return s.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)
|
lines := make([]string, 0, 100)
|
||||||
send := func(line string) {
|
send := func(line string) {
|
||||||
lines = append(lines, line)
|
lines = append(lines, line)
|
||||||
@ -106,7 +107,7 @@ func (device *Device) IpcGetOperation(socket *bufio.Writer) *IPCError {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (device *Device) IpcSetOperation(socket *bufio.Reader) *IPCError {
|
func (device *Device) IpcSetOperation(socket *bufio.Reader) error {
|
||||||
scanner := bufio.NewScanner(socket)
|
scanner := bufio.NewScanner(socket)
|
||||||
logError := device.log.Error
|
logError := device.log.Error
|
||||||
logDebug := device.log.Debug
|
logDebug := device.log.Debug
|
||||||
@ -421,10 +422,20 @@ func (device *Device) IpcHandle(socket net.Conn) {
|
|||||||
|
|
||||||
switch op {
|
switch op {
|
||||||
case "set=1\n":
|
case "set=1\n":
|
||||||
status = device.IpcSetOperation(buffered.Reader)
|
err = device.IpcSetOperation(buffered.Reader)
|
||||||
|
if err != nil && !errors.As(err, &status) {
|
||||||
|
// should never happen
|
||||||
|
device.log.Error.Println("Invalid UAPI error:", err)
|
||||||
|
status = &IPCError{1}
|
||||||
|
}
|
||||||
|
|
||||||
case "get=1\n":
|
case "get=1\n":
|
||||||
status = device.IpcGetOperation(buffered.Writer)
|
err = device.IpcGetOperation(buffered.Writer)
|
||||||
|
if err != nil && !errors.As(err, &status) {
|
||||||
|
// should never happen
|
||||||
|
device.log.Error.Println("Invalid UAPI error:", err)
|
||||||
|
status = &IPCError{1}
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
device.log.Error.Println("Invalid UAPI operation:", op)
|
device.log.Error.Println("Invalid UAPI operation:", op)
|
||||||
|
Loading…
Reference in New Issue
Block a user