Name a nested payload's problems with PayloadError.Within
The notify module names the problems of an action, an object inside its payload, by the action's place in the payload. The module routes need the same for a payload sent inside a larger request body, so the naming becomes a method of PayloadError. What notify reports does not change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2e291817d3
commit
cbac0b5f03
3 files changed
+35
-9
No files matched your search
@@ -32,6 +32,22 @@ func (e *PayloadError) Error() string {
|
||||
return "invalid payload: " + strings.Join(e.Problems, "; ")
|
||||
}
|
||||
|
||||
// Within returns the problems as problems of field, the place that holds
|
||||
// the payload in a larger object: "done[0]: ..." becomes
|
||||
// "field.done[0]: ...", and a problem with the whole payload,
|
||||
// "body: ...", becomes "field: ...".
|
||||
func (e *PayloadError) Within(field string) []string {
|
||||
problems := make([]string, len(e.Problems))
|
||||
for i, problem := range e.Problems {
|
||||
if rest, ok := strings.CutPrefix(problem, "body: "); ok {
|
||||
problems[i] = field + ": " + rest
|
||||
continue
|
||||
}
|
||||
problems[i] = field + "." + problem
|
||||
}
|
||||
return problems
|
||||
}
|
||||
|
||||
// Env is what a module may know when it builds a receipt: the time it is
|
||||
// built at, how times print and how notifications are laid out. A module
|
||||
// never reads the clock itself, so that its output is reproducible.
|
||||
|
||||
Reference in new issue
Block a user