Skip to content

Conversation

@bencoppock
Copy link
Contributor

The decode false option is currently slightly misleading. Rather than skipping decoding, it just returns the raw values from the register (or more accurately, the raw value returned by whatever modbus communication library you're using).

This PR changes that so we actually skip decoding when decode: false is passed. This seems like a better option for cases where some value isn't decoding properly, and we're digging in to see what the raw value was.

Because it was slightly simpler, we were just always decoding before,
and then we were returning the raw or decoded value depending on what
had been requested. But there may be instances where the decode logic
is failing to handle a value, and it may be beneficial to _not_ run
the decode logic at all…hence this change.
@bencoppock bencoppock requested a review from Copilot July 26, 2025 22:16
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR changes the behavior of the decode: false option to actually skip the decoding process entirely, rather than just returning raw encoded values after decoding. This provides better debugging capabilities when decoding fails by allowing users to access truly raw register values.

  • Changes decode: false to bypass the decoding logic completely
  • Adds error handling for decoding failures with descriptive error messages
  • Refactors the decode function to conditionally apply decoding based on the option

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
lib/modboss.ex Implements conditional decoding logic and improves error handling for decode failures
test/modboss_test.exs Adds comprehensive tests for decode error handling and raw value bypass functionality

@bencoppock bencoppock merged commit 55f8285 into main Jul 26, 2025
1 check passed
@bencoppock bencoppock deleted the skip-decoding-if-decode-false branch July 26, 2025 22:20
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.

2 participants