normalizers: Updated error handling within the JSON helper function.

This commit is contained in:
2026-01-15 20:17:46 -06:00
parent d8db58c004
commit a341aee5df
3 changed files with 7 additions and 4 deletions

View File

@@ -42,6 +42,10 @@ func DecodeJSONPayload[T any](in event.Event) (T, error) {
// label should be short and specific, e.g. "openweather observation".
// outSchema should be the canonical schema constant.
// build should contain ONLY provider/domain mapping logic.
//
// Error policy:
// - NormalizeJSON wraps ALL failures with consistent context: "<label> normalize: <stage>: ..."
// - build() should return specific errors without repeating the label prefix.
func NormalizeJSON[T any, P any](
in event.Event,
label string,
@@ -55,8 +59,7 @@ func NormalizeJSON[T any, P any](
payload, effectiveAt, err := build(parsed)
if err != nil {
// build() should already include provider-specific context where appropriate.
return nil, err
return nil, fmt.Errorf("%s normalize: build: %w", label, err)
}
out, err := Finalize(in, outSchema, payload, effectiveAt)