Skip to content

chore: report validation errors as validation errors - #4072

Merged
turip merged 1 commit into
mainfrom
chore/report-validation-errors-as-validation-errors
Apr 2, 2026
Merged

turip merged 1 commit into
mainfrom
chore/report-validation-errors-as-validation-errors

Conversation

@turip

@turip turip commented Apr 2, 2026 •

Copy link
Copy Markdown
Member

Overview

report validation errors as validation errors

Notes for reviewer

Summary by CodeRabbit

  • Refactor
    • Standardized validation error handling across the billing charges module by wrapping validation failures with a centralized error type framework. Individual and aggregated validation errors now return wrapped error objects instead of raw errors, improving error consistency and handling semantics throughout the module.

@turip
turip requested a review from a team as a code owner April 2, 2026 15:30
@coderabbitai

coderabbitai Bot commented Apr 2, 2026 •

Copy link
Copy Markdown
Contributor

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This PR systematically refactors validation error handling across the billing/charges module. Instead of returning raw fmt.Errorf(...) or errors.Join(...), validation methods now consistently wrap errors using centralized constructors: models.NewGenericValidationError() for single validation failures and models.NewNillableGenericValidationError() for aggregated errors.

Changes

Cohort / File(s) Summary
Core Charge Validation
openmeter/billing/charges/adapter.go, openmeter/billing/charges/charge.go, openmeter/billing/charges/events.go, openmeter/billing/charges/patch.go, openmeter/billing/charges/service.go
Wrapped fmt.Errorf(...) and errors.Join(...) returns with centralized error constructors across Validate() methods. Service.go also updates multiple input validators with consistent nillable generic error wrapping.
Credit Purchase Validation
openmeter/billing/charges/creditpurchase/adapter.go, openmeter/billing/charges/creditpurchase/chargecreditpurchase.go, openmeter/billing/charges/creditpurchase/service.go, openmeter/billing/charges/creditpurchase/settlement.go
Standardized error returns in input and domain model validators to use wrapped error constructors instead of raw joined errors.
Flat Fee Validation
openmeter/billing/charges/flatfee/adapter.go, openmeter/billing/charges/flatfee/charge.go, openmeter/billing/charges/flatfee/handler.go, openmeter/billing/charges/flatfee/service.go, openmeter/billing/charges/flatfee/statemachine.go
Applied consistent error wrapping across flat fee charge, intent, and state validators; handler input validators; and status validators.
Meta & Patch Operations
openmeter/billing/charges/meta/adapter.go, openmeter/billing/charges/meta/charge.go, openmeter/billing/charges/meta/intent.go, openmeter/billing/charges/meta/patchdelete.go, openmeter/billing/charges/meta/patchextend.go, openmeter/billing/charges/meta/patchshrink.go, openmeter/billing/charges/meta/resource.go, openmeter/billing/charges/meta/subscription.go
Wrapped charge metadata, patch policy, and subscription validators to use models error constructors for both single and aggregated validation failures.
Payment & Model Validation
openmeter/billing/charges/models/payment/external.go, openmeter/billing/charges/models/payment/invoiced.go, openmeter/billing/charges/models/payment/models.go, openmeter/billing/charges/models/creditrealization/models.go, openmeter/billing/charges/models/invoicedusage/stdinvoice.go, openmeter/billing/charges/models/ledgertransaction/ledger.go
Standardized error returns in payment validators (status, base, external, invoiced) and model validators (credit realization, accrued usage, ledger references).
Usage-Based Validation
openmeter/billing/charges/usagebased/charge.go, openmeter/billing/charges/usagebased/handler.go, openmeter/billing/charges/usagebased/realizationrun.go, openmeter/billing/charges/usagebased/service.go, openmeter/billing/charges/usagebased/statemachine.go
Wrapped usage-based charge, realization run, and input validators with standardized error constructors; updated status and multi-error aggregation handling.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

release-note/misc, area/billing

Suggested reviewers

  • tothandras
  • GAlexIHU
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly describes the main change: wrapping raw validation errors with proper validation error types throughout the codebase.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/report-validation-errors-as-validation-errors

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@turip
turip enabled auto-merge (squash) April 2, 2026 15:31
@turip turip added the release-note/bug-fix Release note: Bug Fixes label Apr 2, 2026
@turip
turip merged commit 494829a into main Apr 2, 2026
25 of 26 checks passed
@turip
turip deleted the chore/report-validation-errors-as-validation-errors branch April 2, 2026 15:36

This branch was previously deployed

1 inactive deployment
dev — 8c50804b Deployed Apr 2, 2026 by turip via Migration Checks #13170
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/bug-fix Release note: Bug Fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants