Skip to content

Validate options at startup instead of throwing NullReferenceException #42

Description

@matthewdevenny

Problem

A missing/empty BucketName throws a NullReferenceException from the NatsCache constructor (src/NatsDistributedCache/NatsCache.cs). This surfaces as a confusing error at first use rather than a clear configuration failure.

Proposal

Validate options at startup using the options pattern:

services.AddOptions<NatsCacheOptions>()
    .Validate(o => !string.IsNullOrWhiteSpace(o.BucketName), "BucketName must be set")
    .ValidateOnStart();

(or an IValidateOptions<NatsCacheOptions> implementation). Remove the NullReferenceException throw.

Acceptance criteria

  • Empty/whitespace BucketName fails fast at startup with a descriptive OptionsValidationException.
  • No NullReferenceException path remains.

Good first issue.

Metadata

Metadata

Assignees

No one assigned

    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