WrapInputStatErrorTyped wraps a FileIO.Stat/Open error for input file validation, returning a typed validation error with the appropriate message: - Path validation failures → "unsafe file path: ..." - Other errors → readMsg prefix (default "cannot read file") Pass an optional readMsg to override t
(err error, readMsg ...string)
| 604 | // |
| 605 | // Pass an optional readMsg to override the non-path-validation message prefix. |
| 606 | func WrapInputStatErrorTyped(err error, readMsg ...string) error { |
| 607 | if err == nil { |
| 608 | return nil |
| 609 | } |
| 610 | if errors.Is(err, fileio.ErrPathValidation) { |
| 611 | return errs.NewValidationError(errs.SubtypeInvalidArgument, "unsafe file path: %s", err). |
| 612 | WithCause(err) |
| 613 | } |
| 614 | msg := "cannot read file" |
| 615 | if len(readMsg) > 0 && readMsg[0] != "" { |
| 616 | msg = readMsg[0] |
| 617 | } |
| 618 | return errs.NewValidationError(errs.SubtypeInvalidArgument, "%s: %s", msg, err). |
| 619 | WithCause(err) |
| 620 | } |
| 621 | |
| 622 | // WrapSaveErrorTyped maps a FileIO.Save error to typed validation/internal errors. |
| 623 | // Non-path failures always emit the canonical "internal" wire type; call sites |