Skip to content

Commit

Permalink
Make Open return a nil interface on failure
Browse files Browse the repository at this point in the history
Closes #154

Signed-off-by: Daniel Lublin <[email protected]>
  • Loading branch information
quite authored and cmaglie committed Aug 9, 2023
1 parent a2c15aa commit d2a59a6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion serial.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,13 @@ type ModemOutputBits struct {

// Open opens the serial port using the specified modes
func Open(portName string, mode *Mode) (Port, error) {
return nativeOpen(portName, mode)
port, err := nativeOpen(portName, mode)
if err != nil {
// Return a nil interface, for which var==nil is true (instead of
// a nil pointer to a struct that satisfies the interface).
return nil, err
}
return port, err
}

// GetPortsList retrieve the list of available serial ports
Expand Down

0 comments on commit d2a59a6

Please sign in to comment.