Validate normalize retry diagnostics

This commit is contained in:
2026-07-26 02:43:28 +00:00
parent d3c4d6f133
commit 80ec939383
5 changed files with 154 additions and 10 deletions

View File

@@ -0,0 +1,34 @@
package pipeline
import (
"errors"
"strings"
"unicode/utf8"
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
)
func validateNormalizeRetry(retry *contracts.NormalizeRetry) error {
if retry == nil {
return errors.New("normalize retry directive is missing")
}
if !utf8.ValidString(retry.ReasonCode) {
return errors.New("normalize retry directive reason code has invalid UTF-8")
}
if strings.TrimSpace(retry.ReasonCode) == "" {
return errors.New("normalize retry directive reason code is blank")
}
if len(retry.ReasonCode) > contracts.MaxNormalizeRetryReasonCodeBytes {
return errors.New("normalize retry directive reason code exceeds maximum length")
}
if !utf8.ValidString(retry.Message) {
return errors.New("normalize retry directive message has invalid UTF-8")
}
if strings.TrimSpace(retry.Message) == "" {
return errors.New("normalize retry directive message is blank")
}
if len(retry.Message) > contracts.MaxNormalizeRetryMessageBytes {
return errors.New("normalize retry directive message exceeds maximum length")
}
return nil
}