Skip to content

[Order 05][P2] Harden duplicate detection and null binary materialization #62

@AGiorgetti

Description

@AGiorgetti

Priority order

Order: 05 of 09
Priority: P2 correctness

Problem

Provider error handling and binary materialization have fragile edge cases.

Evidence:

  • src/NEventStore.Persistence.Sql/SqlDialects/MySqlDialect.cs:43
  • MySQL duplicate detection reflects a Number property and immediately casts it.
  • src/NEventStore.Persistence.Sql/CommitExtensions.cs:87
  • GetByteArray returns [default] for null/DBNull.Value.

Impact

  • MySQL can mask non-provider exceptions with NullReferenceException or invalid casts during error handling.
  • Nullable Headers values can be deserialized from one zero byte instead of returning default, which can fail for legacy rows or manually inserted rows.

Mandatory test-first workflow

  • Add tests first to reproduce or verify each behavior.
  • Add a unit test proving MySqlDialect.IsDuplicate(new Exception(...)) returns false and does not throw.
  • Add a materialization test for a commit row with Headers = NULL.
  • Do not change production code until the tests capture the expected behavior.

Proposed action

  • Guard MySQL IsDuplicate for missing or non-int Number.
  • Prefer provider-specific exception checks where available.
  • Return [] for null and DBNull.Value in GetByteArray.

Acceptance criteria

  • Duplicate detection does not throw for unrelated exception types.
  • Null headers materialize as default/empty headers behavior without deserialization failure.
  • Existing duplicate-commit behavior remains covered.

Source: docs/Project-Analysis-Issue-Drafts.md.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions