ReadInputFile reads path through fileIO. Open/read failures are wrapped with path context; fileio.ErrPathValidation remains matchable with errors.Is.
(fileIO fileio.FileIO, path string)
| 78 | // ReadInputFile reads path through fileIO. Open/read failures are wrapped with |
| 79 | // path context; fileio.ErrPathValidation remains matchable with errors.Is. |
| 80 | func ReadInputFile(fileIO fileio.FileIO, path string) ([]byte, error) { |
| 81 | if fileIO == nil { |
| 82 | return nil, fmt.Errorf("file input is not available in this context") |
| 83 | } |
| 84 | f, err := fileIO.Open(path) |
| 85 | if err != nil { |
| 86 | return nil, wrapInputFileError(path, err) |
| 87 | } |
| 88 | defer f.Close() |
| 89 | data, err := io.ReadAll(f) |
| 90 | if err != nil { |
| 91 | return nil, wrapInputFileError(path, err) |
| 92 | } |
| 93 | return data, nil |
| 94 | } |
| 95 | |
| 96 | func wrapInputFileError(path string, err error) error { |
| 97 | if errors.Is(err, fileio.ErrPathValidation) { |
no test coverage detected