Make Open return a nil interface on failure

Closes #154

Signed-off-by: Daniel Lublin <daniel@lublin.se>
This commit is contained in:
Daniel Lublin
2023-02-09 08:22:51 +01:00
committed by Cristian Maglie
parent a2c15aa1f5
commit d2a59a651d

View File

@@ -80,7 +80,13 @@ type ModemOutputBits struct {
// Open opens the serial port using the specified modes // Open opens the serial port using the specified modes
func Open(portName string, mode *Mode) (Port, error) { 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 // GetPortsList retrieve the list of available serial ports