Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client: undo set read-timeout for failed GetNameVersion #9

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cobratbq
Copy link

@cobratbq cobratbq commented Jun 4, 2024

Undo temporary read-timeout in GetNameVersion(). (Note that code in this function does not take into account the possibility for another read-timeout already set. This fix only makes GetNameVersion() behave as expected under the same assumptions already present.)

update: you could consider calling panic on the error of tk.conn.SetReadTimeout. The only error possible seems to be for invalid values, and those are handled already. The panic would never trigger, but it would alert you in case the serial-port API changes unexpectedly.

  • you can remove return-type for SetReadTimeout,
  • panic in case of error at tk.conn.SetReadTimeout,
  • in GetNameVersion, call defer SetReadTimeout(0) immediately after SetReadTimeout(2),
  • remove other individual calls SetReadTimeout(0) as defer already handles every exit,

@quite
Copy link
Contributor

quite commented Jun 17, 2024

Resetting the read timeout to 0 before returning error looks like a good idea in general (no matter what this patch might be otherwise needed for).

And the update regarding panic:ing on SetReadTimeout (and simplifying of code paths) also seems reasonable, if indeed the only case it can error is on being passed an illegal value.

@dehanj
Copy link
Member

dehanj commented Jun 28, 2024

update: you could consider calling panic on the error of tk.conn.SetReadTimeout. The only error possible seems to be for invalid values, and those are handled already. The panic would never trigger, but it would alert you in case the serial-port API changes unexpectedly.

you can remove return-type for SetReadTimeout,
panic in case of error at tk.conn.SetReadTimeout,
in GetNameVersion, call defer SetReadTimeout(0) immediately after SetReadTimeout(2),
remove other individual calls SetReadTimeout(0) as defer already handles every exit,

I like this approach, very clean. As you say, it seems to only have one possible error, which is already handled.
This is however a breaking change. Will discuss here to see how to go about it.

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.

3 participants