Skip to content

Improve Required Field Errors (DynamoMappingException) #26

@j-d-ha

Description

@j-d-ha

Priority: P2 - Important
Tier: 3 - Advanced Features
Effort: Medium (6-8 hours)

Already In Codebase

  • Requiredness is already calculated and passed into runtime Get methods:
    • Field override + global default requiredness: src/LayeredCraft.DynamoMapper.Generators/PropertyMapping/PropertyMappingSpecBuilder.cs
    • Runtime behavior on missing keys:
      • Requiredness.Required and Requiredness.InferFromNullability currently throw InvalidOperationException.
      • Requiredness.Optional returns a DynamoDB NULL value.
      • src/LayeredCraft.DynamoMapper.Runtime/AttributeValueExtensions/UtilAttributeValueExtensions.cs
  • There are tests that exercise requiredness override scenarios:
    • test/LayeredCraft.DynamoMapper.Generators.Tests/DynamoFieldVerifyTests.cs

Goal

Improve required field validation behavior in FromItem:

  • Ensure requiredness rules are consistently enforced.
  • Throw a purpose-built DynamoMappingException (already exists) with useful context (mapper/type/field/member).

Implementation notes

  • Prefer updating runtime Get helpers to throw DynamoMappingException instead of InvalidOperationException.
  • Include:
    • mapper name
    • target type
    • field name
    • member name
    • details about what was missing
  • Ensure behavior is consistent for:
    • required non-nullable members
    • [DynamoField(Required = true/false)] overrides
    • DefaultRequiredness mapper option

Tests

  • Add verify/behavior tests for missing required fields that validate the thrown exception type/message.

Acceptance criteria

  • Missing required fields throw DynamoMappingException with actionable details.
  • Optional fields remain optional and do not throw.
  • Tests cover both required and optional cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions