Skip to content

Comments

Jp/fix linter (ignore)#91

Draft
JPHutchins wants to merge 4 commits intomainfrom
jp/fix-linter
Draft

Jp/fix linter (ignore)#91
JPHutchins wants to merge 4 commits intomainfrom
jp/fix-linter

Conversation

@JPHutchins
Copy link
Collaborator

No description provided.

JaagupAverin and others added 4 commits December 1, 2025 13:03
Additionally fixes an issue where `ValidationError(error)` constructor would re-raise an exception because it requires additional arguments.
@JaagupAverin
Copy link
Contributor

Looks good, thanks.
Personally I like 'raise from none' pattern to reduce error clutter, but it's up to you.

@JPHutchins
Copy link
Collaborator Author

Looks good, thanks.
Personally I like 'raise from none' pattern to reduce error clutter, but it's up to you.

That is nice, I do think it's a good fit here, feel free to change it back in the PR. Now, if only we could just remove exceptions from the language and call it a day!

Copy link
Contributor

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 improves SMP frame parsing diagnostics by introducing a dedicated validation exception that includes detailed context, and updates the lint alias to show Black diffs.

Changes:

  • Add SMPValidationException to carry a short message plus detailed parsing diagnostics.
  • Enhance SMPClient.request() to collect Pydantic validation errors across candidate response/error types and log a hexdump + error breakdown before raising SMPValidationException.
  • Update the lint alias to run black --check --diff.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
smpclient/exceptions.py Adds a new exception type for response validation failures.
smpclient/init.py Implements detailed validation error formatting/logging and raises SMPValidationException on parse failure.
envr-default Updates the lint alias to include Black --diff output.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.



def _hexdump_ascii(data: bytes) -> str:
"""Python 3.12+ has builtin hexdump, prior to that we need to reinvent the wheel."""
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

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

The _hexdump_ascii docstring claims Python 3.12+ has a built-in hexdump; the stdlib doesn't provide a general-purpose bytes hexdump helper. Consider updating the docstring to reflect why this helper exists (e.g., for readable debug logging) without referencing a non-existent built-in.

Suggested change
"""Python 3.12+ has builtin hexdump, prior to that we need to reinvent the wheel."""
"""Return a human-readable hex + ASCII dump of the given bytes for debug logging."""

Copilot uses AI. Check for mistakes.
Comment on lines +234 to +236
msg, details = _smp_validation_error_message(header, frame, errs)
logger.error(msg + details)
raise SMPValidationException(msg, details)
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

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

request() now raises SMPValidationException instead of bubbling a pydantic.ValidationError when the frame can't be parsed. There are existing SMPClient request tests, but none covering this new failure mode; please add/adjust a test to assert the new exception type and (at minimum) that details contains header/frame context.

Copilot uses AI. Check for mistakes.
err_type = err["type"]
msg = err["msg"]
loc = ".".join(str(x) for x in err["loc"])
lines.append(f"\t\t[{err_type}] {msg}: {loc}; input: {err['input']})")
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

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

The formatted error line ends with an unmatched closing parenthesis ("... input: ...)"). This will produce confusing log output; remove the trailing ")" or add a corresponding opening delimiter if you intended to wrap the input value.

Suggested change
lines.append(f"\t\t[{err_type}] {msg}: {loc}; input: {err['input']})")
lines.append(f"\t\t[{err_type}] {msg}: {loc}; input: {err['input']}")

Copilot uses AI. Check for mistakes.
def _smp_validation_error_message(
header: smpheader.Header,
frame: bytes,
errs: dict[type[smpmsg.Response], ValidationError],
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

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

Type annotations for errs are inconsistent: _smp_validation_error_message() declares errs: dict[type[smpmsg.Response], ValidationError], but request() builds errs: dict[Type, ValidationError] and includes error classes (_ErrorV1/_ErrorV2). This is likely to fail mypy due to dict invariance. Align the types (e.g., make both use dict[type[object] | type[Any], ValidationError], or tighten request() to the exact common base type).

Suggested change
errs: dict[type[smpmsg.Response], ValidationError],
errs: dict[Type, ValidationError],

Copilot uses AI. Check for mistakes.
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