Skip to content

fix: CommandRecord.trim raises OverflowError instead of S2ClientError#29

Merged
quettabit merged 1 commit intomainfrom
qb/iss-8
Apr 11, 2026
Merged

fix: CommandRecord.trim raises OverflowError instead of S2ClientError#29
quettabit merged 1 commit intomainfrom
qb/iss-8

Conversation

@quettabit
Copy link
Copy Markdown
Member

closes #8

@quettabit quettabit requested a review from a team as a code owner April 11, 2026 05:35
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 11, 2026

Greptile Summary

Adds @fallible to CommandRecord.trim so that OverflowError (raised by int.to_bytes when given a negative or oversized integer) is caught and re-raised as S2ClientError instead of leaking a raw Python exception — consistent with the pattern already used by Endpoints.from_env.

Confidence Score: 5/5

Safe to merge; the one-line fix is correct and consistent with the existing @Fallible pattern in the codebase.

The change is minimal and correct — @Fallible is already used elsewhere (e.g. Endpoints.from_env) and is purpose-built to convert non-S2Error exceptions into S2ClientError. The only finding is a P2 suggestion to add a regression test, which does not block merge.

No files require special attention.

Important Files Changed

Filename Overview
src/s2_sdk/_types.py Adds @fallible decorator to CommandRecord.trim so OverflowError from int.to_bytes is wrapped in S2ClientError; fix is correct and consistent with existing codebase patterns.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["CommandRecord.trim(desired_first_seq_num)"] --> B["@fallible wrapper"]
    B --> C["desired_first_seq_num.to_bytes(8, 'big')"]
    C -- "valid int (0 .. 2^64-1)" --> D["Return Record with TRIM header"]
    C -- "OverflowError\n(negative or too large)" --> E["fallible catches Exception"]
    E -- "not S2Error" --> F["raise S2ClientError(e)"]
    D --> G["Caller receives Record"]
    F --> H["Caller receives S2ClientError"]
Loading

Comments Outside Diff (1)

  1. src/s2_sdk/_types.py, line 275-284 (link)

    P2 Missing test for the fixed behaviour

    tests/test_validators.py already has test_fencing_token_rejects_too_long as a unit-level regression guard for CommandRecord.fence. A parallel test for CommandRecord.trim with an out-of-range value (e.g. -1) would lock in the fix and prevent regressions without requiring an integration environment.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: src/s2_sdk/_types.py
    Line: 275-284
    
    Comment:
    **Missing test for the fixed behaviour**
    
    `tests/test_validators.py` already has `test_fencing_token_rejects_too_long` as a unit-level regression guard for `CommandRecord.fence`. A parallel test for `CommandRecord.trim` with an out-of-range value (e.g. `-1`) would lock in the fix and prevent regressions without requiring an integration environment.
    
    How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/s2_sdk/_types.py
Line: 275-284

Comment:
**Missing test for the fixed behaviour**

`tests/test_validators.py` already has `test_fencing_token_rejects_too_long` as a unit-level regression guard for `CommandRecord.fence`. A parallel test for `CommandRecord.trim` with an out-of-range value (e.g. `-1`) would lock in the fix and prevent regressions without requiring an integration environment.

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "initial commit" | Re-trigger Greptile

@quettabit quettabit merged commit f394b1e into main Apr 11, 2026
5 checks passed
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.

[Detail Bug] SDK: CommandRecord.trim raises raw OverflowError instead of S2ClientError for invalid sequence numbers

1 participant