Skip to content

[DEV-1038] fix: add missing no stream case to expected revision error handling#363

Merged
w1am merged 2 commits intotrunkfrom
w1am/dev-1038-incorrect-expected-state-displayed-in
Feb 3, 2026
Merged

[DEV-1038] fix: add missing no stream case to expected revision error handling#363
w1am merged 2 commits intotrunkfrom
w1am/dev-1038-incorrect-expected-state-displayed-in

Conversation

@w1am
Copy link
Contributor

@w1am w1am commented Feb 3, 2026

PR Type

fixes: #362

Bug fix, Tests


Description

  • Add missing EXPECTED_NO_STREAM case to error handling in AppendToStream

  • Previously fell through to else branch, incorrectly returning streamRevision

  • Expand test coverage with multiple new test cases for stream state scenarios

  • Refactor existing test for improved readability and code organization


Diagram Walkthrough

flowchart LR
  A["AppendToStream Error Response"] -->|EXPECTED_ANY| B["StreamState.any()"]
  A -->|EXPECTED_STREAM_EXISTS| C["StreamState.streamExists()"]
  A -->|EXPECTED_NO_STREAM| D["StreamState.noStream()"]
  A -->|Other| E["StreamState.streamRevision()"]
  D --> F["Correct State Returned"]
  E --> G["Tests Validate All Cases"]
Loading

File Walkthrough

Relevant files
Bug fix
AppendToStream.java
Handle EXPECTED_NO_STREAM in error response parsing           

src/main/java/io/kurrent/dbclient/AppendToStream.java

  • Add handling for EXPECTED_NO_STREAM case in WrongExpectedVersion error
    response parsing
  • Return StreamState.noStream() instead of falling through to default
    streamRevision case
  • Add blank line for code formatting consistency
+3/-0     
Tests
AppendTests.java
Expand append tests with comprehensive stream state coverage

src/test/java/io/kurrent/dbclient/streams/AppendTests.java

  • Refactor testAppendSingleEventNoStream() for improved readability and
    removed intermediate variable
  • Add testAppendMultipleEventsAtOnce() to test appending multiple events
    in single operation
  • Add testStreamStateOptimisticConcurrency() to validate all stream
    state scenarios and error cases
  • Add helper methods: createTestEvent(), appendEvent(), and
    assertWrongExpectedVersion()
+66/-13 
Formatting
README.md
Minor formatting adjustment                                                           

README.md

  • Add blank line at beginning of file
+1/-0     

@linear
Copy link

linear bot commented Feb 3, 2026

@w1am w1am force-pushed the w1am/dev-1038-incorrect-expected-state-displayed-in branch from be3330b to bdd8d62 Compare February 3, 2026 17:10
@qodo-code-review
Copy link

qodo-code-review bot commented Feb 3, 2026

PR Compliance Guide 🔍

Below is a summary of compliance checks for this PR:

Security Compliance
🟢
No security concerns identified No security vulnerabilities detected by AI analysis. Human verification advised for critical code.
Ticket Compliance
🎫 No ticket provided
  • Create ticket/issue
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
🟢
Generic: Comprehensive Audit Trails

Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Meaningful Naming and Self-Documenting Code

Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Robust Error Handling and Edge Case Management

Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Error Handling

Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Logging Practices

Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Security-First Input Validation and Data Handling

Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

  • Update
Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label

@qodo-code-review
Copy link

qodo-code-review bot commented Feb 3, 2026

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
Improve exception handling in test helper

Improve exception handling in the assertWrongExpectedVersion test helper to
correctly manage InterruptedException by catching a generic Exception and
rethrowing its cause.

src/test/java/io/kurrent/dbclient/streams/AppendTests.java [92-103]

 default void assertWrongExpectedVersion(KurrentDBClient client, String streamName, StreamState state, StreamState expectedState, StreamState actualState) {
     WrongExpectedVersionException ex = Assertions.assertThrows(WrongExpectedVersionException.class, () -> {
         try {
             appendEvent(client, streamName, state);
-        } catch (java.util.concurrent.ExecutionException e) {
-            throw e.getCause();
+        } catch (Exception e) {
+            if (e.getCause() != null) {
+                throw e.getCause();
+            }
+            throw e;
         }
     });
     Assertions.assertEquals(streamName, ex.getStreamName());
     Assertions.assertEquals(expectedState, ex.getExpectedState());
     Assertions.assertEquals(actualState, ex.getActualState());
 }
  • Apply / Chat
Suggestion importance[1-10]: 6

__

Why: The suggestion correctly identifies that InterruptedException is not handled in the assertWrongExpectedVersion test helper, and proposes a more robust implementation that correctly handles different exception types from the asynchronous operation.

Low
  • Update

Handle EXPECTED_NO_STREAM case in AppendToStream error response parsing. Previously this case fell through to the else branch, incorrectly returning a streamRevision state instead of noStream.
@w1am w1am force-pushed the w1am/dev-1038-incorrect-expected-state-displayed-in branch from bdd8d62 to 4ca1758 Compare February 3, 2026 17:15
@w1am w1am merged commit 3fe9998 into trunk Feb 3, 2026
42 checks passed
@w1am w1am deleted the w1am/dev-1038-incorrect-expected-state-displayed-in branch February 3, 2026 17:19
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

@w1am 👉 Created pull request targeting release/v1.1: #367

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect expected state displayed in WrongExpectedVersionException

1 participant