Skip to content

Add registry validation and structured errors#3479

Merged
dmjb merged 2 commits intomainfrom
registry-validation-and-errors
Jan 28, 2026
Merged

Add registry validation and structured errors#3479
dmjb merged 2 commits intomainfrom
registry-validation-and-errors

Conversation

@dmjb
Copy link
Copy Markdown
Contributor

@dmjb dmjb commented Jan 28, 2026

Summary

This PR introduces comprehensive validation for registry configurations and structured error types for better error handling and classification.

This is part 1 of 3 PRs that improve registry API error handling:

  1. This PR: Add validation infrastructure and error types
  2. Introduce service layer and improve API/CLI error handling
  3. Update E2E tests

Changes

Validation Infrastructure

  • Add 5-second timeout support to HTTP client builder (pkg/networking/http_client.go)
  • Add registry validation functions in pkg/registry/provider_remote.go:
    • isValidRegistryJSON(): Validates registry JSON structure
    • registryHasServers(): Ensures registry contains at least one server
  • Add comprehensive validation tests in pkg/registry/provider_test.go

Structured Error Types

  • Introduce new error types in pkg/config/errors.go:
    • RegistryError: Wraps registry errors with context (type, URL)
    • ErrRegistryTimeout: Sentinel error for timeout scenarios
    • ErrRegistryUnreachable: Sentinel error for connectivity issues
    • ErrRegistryValidationFailed: Sentinel error for validation failures
  • Add error tests in pkg/config/errors_test.go

Error Classification

  • Add classifyNetworkError() in pkg/config/registry.go to classify network errors
  • Update setRegistryURL(), setRegistryFile(), setRegistryAPI() to return RegistryError types
  • Update tests to reflect new error handling

Benefits

  1. Better error context: Errors now include registry type and URL
  2. Structured error handling: Can use errors.Is() and errors.As() for error inspection
  3. Foundation for proper HTTP status codes: Enables mapping to 502 (validation) and 504 (timeout)
  4. Improved user experience: Downstream changes can provide better error messages

Testing

  • Added comprehensive unit tests for validation logic
  • Added error classification tests
  • Updated existing tests to work with new error types

🤖 Generated with Claude Code

This change introduces comprehensive validation for registry configurations
and structured error types for better error handling and classification.

Changes:
- Add 5-second timeout support to HTTP client builder
- Add registry validation in provider_remote.go (isValidRegistryJSON, registryHasServers)
- Add comprehensive validation tests in provider_test.go
- Introduce structured error types (RegistryError, ErrRegistryTimeout, etc.)
- Add error classification logic (classifyNetworkError)
- Update registry.go to return RegistryError types with proper context
- Update tests to reflect new error handling

This lays the foundation for improved error handling in the registry API
and CLI, enabling proper HTTP status codes (502, 504) based on error type.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov bot commented Jan 28, 2026

Codecov Report

❌ Patch coverage is 75.75758% with 24 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.18%. Comparing base (018e2c0) to head (c9a6f77).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
pkg/config/registry.go 67.85% 17 Missing and 1 partial ⚠️
pkg/registry/provider_remote.go 79.31% 3 Missing and 3 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3479   +/-   ##
=======================================
  Coverage   65.17%   65.18%           
=======================================
  Files         397      398    +1     
  Lines       38626    38706   +80     
=======================================
+ Hits        25173    25229   +56     
- Misses      11499    11521   +22     
- Partials     1954     1956    +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions github-actions bot added size/M Medium PR: 300-599 lines changed and removed size/M Medium PR: 300-599 lines changed labels Jan 28, 2026
@dmjb dmjb merged commit 6c2a0c5 into main Jan 28, 2026
35 checks passed
@dmjb dmjb deleted the registry-validation-and-errors branch January 28, 2026 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Medium PR: 300-599 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants