Skip to content

Commit 65f1869

Browse files
committed
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 <[email protected]>
1 parent e852f4c commit 65f1869

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

device/uapi.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package device
77

88
import (
99
"bufio"
10+
"errors"
1011
"fmt"
1112
"io"
1213
"net"
@@ -31,7 +32,7 @@ func (s IPCError) ErrorCode() int64 {
3132
return s.int64
3233
}
3334

34-
func (device *Device) IpcGetOperation(socket *bufio.Writer) *IPCError {
35+
func (device *Device) IpcGetOperation(socket *bufio.Writer) error {
3536
lines := make([]string, 0, 100)
3637
send := func(line string) {
3738
lines = append(lines, line)
@@ -106,7 +107,7 @@ func (device *Device) IpcGetOperation(socket *bufio.Writer) *IPCError {
106107
return nil
107108
}
108109

109-
func (device *Device) IpcSetOperation(socket *bufio.Reader) *IPCError {
110+
func (device *Device) IpcSetOperation(socket *bufio.Reader) error {
110111
scanner := bufio.NewScanner(socket)
111112
logError := device.log.Error
112113
logDebug := device.log.Debug
@@ -421,10 +422,20 @@ func (device *Device) IpcHandle(socket net.Conn) {
421422

422423
switch op {
423424
case "set=1\n":
424-
status = device.IpcSetOperation(buffered.Reader)
425+
err = device.IpcSetOperation(buffered.Reader)
426+
if !errors.As(err, &status) {
427+
// should never happen
428+
device.log.Error.Println("Invalid UAPI error:", err)
429+
status = &IPCError{1}
430+
}
425431

426432
case "get=1\n":
427-
status = device.IpcGetOperation(buffered.Writer)
433+
err = device.IpcGetOperation(buffered.Writer)
434+
if !errors.As(err, &status) {
435+
// should never happen
436+
device.log.Error.Println("Invalid UAPI error:", err)
437+
status = &IPCError{1}
438+
}
428439

429440
default:
430441
device.log.Error.Println("Invalid UAPI operation:", op)

0 commit comments

Comments
 (0)