Skip to content

feat: config batching and type-annotated errors#17

Open
case-zbz wants to merge 2 commits intomainfrom
feat/config-batching
Open

feat: config batching and type-annotated errors#17
case-zbz wants to merge 2 commits intomainfrom
feat/config-batching

Conversation

@case-zbz
Copy link
Copy Markdown

Summary

  • Config[T] now annotates errors with the type name via reflect.TypeOf, eliminating per-call fmt.Errorf wrapping in application bootstrap
  • Added ConfigAll(loaders ...func() error) error — runs config loaders sequentially, stops on first error

Part 1 of #14 — config batching.

Test plan

  • Existing Config tests pass unchanged
  • Error includes type name (requiredConfig)
  • ConfigAll loads multiple configs and registers all with slush
  • ConfigAll stops on first error (second loader not called)
  • ConfigAll with no loaders returns nil
  • Full test suite passes

🤖 Generated with Claude Code

Config[T] now annotates errors with the type name via reflect so
apps no longer need per-call error wrapping. ConfigAll runs a
sequence of config loaders and stops on the first error.

Part 1 of #14 — config batching.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
wintermute-zbz
wintermute-zbz previously approved these changes Mar 28, 2026
Copy link
Copy Markdown
Contributor

@wintermute-zbz wintermute-zbz left a comment

Choose a reason for hiding this comment

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

Review — #17

Verdict: APPROVE

Two additions: type-annotated config errors and ConfigAll batch helper. Both correct.

Findings

config.go:23reflect.TypeOf(cfg).Name() returns empty string for pointer types.
Not blocking. Config[T] passes &cfg to fig.LoadContext, so T must be a struct value — pointer types would fail at the fig layer before the error annotation runs. Self-protecting. Noting for awareness only.

Assessment

  • Error wrapping uses %w correctly. Chain preserved.
  • ConfigAll is minimal — sequential execution, stops on first error, zero-allocation empty case. Nothing to trim.
  • Tests cover: type name in error message, happy path batching, short-circuit on first error, empty variadic. Good coverage.
  • reflect import is new to the codebase. Cost is justified — no other way to get T's name at runtime in Go generics.
  • No security surface change. No new dependencies.

Clean.

Comment thread config.go Outdated
}
if err := fig.LoadContext(ctx, &cfg, opts...); err != nil {
return err
return fmt.Errorf("config %s: %w", reflect.TypeOf(cfg).Name(), err)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

if we are using reflection we might as well ingest via sentinel - right here I think we should be running sentinel.InspectT so that we don't use reflection directly and the type metadata is available to the service as a whole

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed — switched to sentinel.InspectT so the type metadata is cached in sentinel's registry and available to the service. Error messages now use FQDN. reflect import dropped.

Replaces reflect.TypeOf(cfg).Name() with sentinel.Inspect[T]() so type
metadata is cached and available to the service. Error messages now use
FQDN instead of bare type name.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@wintermute-zbz wintermute-zbz left a comment

Choose a reason for hiding this comment

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

Re-review — #17

Verdict: APPROVE

New commit swaps reflect.TypeOf(cfg).Name() for sentinel.Inspect[T]().FQDN. Better — uses the ecosystem's own type metadata instead of the reflect package. No new dependency (sentinel already in go.mod). reflect import removed.

Previous finding (empty name for pointer types) is resolved — sentinel handles this through its own type introspection.

Tests still pass. Clean.

@zoobzio zoobzio self-requested a review March 28, 2026 06:14
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.

3 participants