Skip to content
This repository has been archived by the owner on Sep 10, 2024. It is now read-only.

lib: Print better error for invalid baudrate #53

Merged

Conversation

har7an
Copy link
Contributor

@har7an har7an commented May 16, 2022

The way the serial crate in use is written it will accept any arbitrary
baudrate and try to configure the interface with it. This can fail if
the underlying hardware doesn't support the given baudrate.

Previously the code would simply output an Error: Invalid argument,
which leaves the user guessing which part of their input was invalid.

This patch adds an additional check on the error type returned by
configuring the serial device. If it returns an InputError, we assume
that in fact the baud rate was invalid (Because that is the only setting
we change) and print a better error message to the user.

The way the serial crate in use is written it will accept any arbitrary
baudrate and try to configure the interface with it. This can fail if
the underlying hardware doesn't support the given baudrate.

Previously the code would simply output an `Error: Invalid argument`,
which leaves the user guessing which part of their input was invalid.

This patch adds an additional check on the error type returned by
configuring the serial device. If it returns an `InputError`, we assume
that in fact the baud rate was invalid (Because that is the only setting
we change) and print a better error message to the user.
@kelnos kelnos merged commit ffdf818 into esp-rs:master May 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants