Skip to content

Preserve errno on Windows serial open failures#866

Open
RobBotic1 wants to merge 1 commit into
pyserial:masterfrom
RobBotic1:patch-1
Open

Preserve errno on Windows serial open failures#866
RobBotic1 wants to merge 1 commit into
pyserial:masterfrom
RobBotic1:patch-1

Conversation

@RobBotic1

Copy link
Copy Markdown

Serial.open() on Windows raised SerialException from a single formatted string, stringifying the WinError and discarding its structured error code. As a result, SerialException.errno was always None on Windows, while the POSIX path populates it via the OSError constructor. Callers could not branch on the failure cause (port not found vs. access denied vs. busy) without parsing the exception message.

Pass the error code as the first positional argument so the OSError base class sets .errno, mirroring serialposix.py. The message format is unchanged, so this is non-breaking for code that only reads str(e).

Fixes #865

Serial.open() on Windows raised SerialException from a single formatted string, stringifying the WinError and discarding its structured error code. As a result, SerialException.errno was always None on Windows, while the POSIX path populates it via the OSError constructor. Callers could not branch on the failure cause (port not found vs. access denied vs. busy) without parsing the exception message.

Pass the error code as the first positional argument so the OSError base class sets .errno, mirroring serialposix.py. The message format is unchanged, so this is non-breaking for code that only reads str(e).

Fixes pyserial#865
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SerialException.errno is populated on POSIX but 'None' on Windows for the same open() failure

1 participant