pkg / term

Package term manages POSIX terminals.
BSD 2-Clause "Simplified" License
393 stars 64 forks source link

Unable to obtain underlying error causing short write. #48

Closed max-okumoto closed 4 years ago

max-okumoto commented 4 years ago

Unable to obtain underlying error causing short write. If the syscall.Write() fails due to an error, the code examines the returned length which is very likely to be less than what was intended to be written and returns io.ErShortWrite.

In my case, the USB serial device was removed and I need to know that the fd is bad, so I can take the appropriate action.

func (t *Term) Write(b []byte) (int, error) { n, e := syscall.Write(t.fd, b) if n < 0 { n = 0 } if n != len(b) { return n, io.ErrShortWrite } if e != nil { return n, &os.PathError{"write", t.name, e} } return n, nil }

davecheney commented 4 years ago

I'm sorry, there's nothing this package can do, the operating system doesn't give an explanation why the write didn't complete, Sorry.