Fix MessagingConfig code review issues (gt-mrqiz, gt-ngoe6, gt-akc4m)

- Add Type field for schema consistency (gt-mrqiz)
- Fix error message inconsistency: all validation errors now wrap sentinel (gt-ngoe6)
- Add missing tests: wrong type, future version, malformed JSON (gt-akc4m)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Steve Yegge
2025-12-28 15:31:09 -08:00
parent 3e863c1431
commit e8d4fcda0b
3 changed files with 46 additions and 5 deletions

View File

@@ -612,6 +612,9 @@ func SaveMessagingConfig(path string, config *MessagingConfig) error {
// validateMessagingConfig validates a MessagingConfig.
func validateMessagingConfig(c *MessagingConfig) error {
if c.Type != "messaging" && c.Type != "" {
return fmt.Errorf("%w: expected type 'messaging', got '%s'", ErrInvalidType, c.Type)
}
if c.Version > CurrentMessagingVersion {
return fmt.Errorf("%w: got %d, max supported %d", ErrInvalidVersion, c.Version, CurrentMessagingVersion)
}
@@ -637,20 +640,20 @@ func validateMessagingConfig(c *MessagingConfig) error {
// Validate queues have at least one worker
for name, queue := range c.Queues {
if len(queue.Workers) == 0 {
return fmt.Errorf("%w: queue '%s' has no workers", ErrMissingField, name)
return fmt.Errorf("%w: queue '%s' workers", ErrMissingField, name)
}
if queue.MaxClaims < 0 {
return fmt.Errorf("queue '%s': max_claims must be non-negative", name)
return fmt.Errorf("%w: queue '%s' max_claims must be non-negative", ErrMissingField, name)
}
}
// Validate announces have at least one reader
for name, announce := range c.Announces {
if len(announce.Readers) == 0 {
return fmt.Errorf("%w: announce '%s' has no readers", ErrMissingField, name)
return fmt.Errorf("%w: announce '%s' readers", ErrMissingField, name)
}
if announce.RetainCount < 0 {
return fmt.Errorf("announce '%s': retain_count must be non-negative", name)
return fmt.Errorf("%w: announce '%s' retain_count must be non-negative", ErrMissingField, name)
}
}