Read file from the workspace and return its contents.
(ctx context.Context, fileName string)
| 72 | |
| 73 | // Read file from the workspace and return its contents. |
| 74 | func ReadFile(ctx context.Context, fileName string) (string, error) { |
| 75 | fs := utils.FS(ctx) |
| 76 | fileBytes, err := afero.ReadFile(fs, fileName) |
| 77 | if err != nil { |
| 78 | return "", err |
| 79 | } |
| 80 | // Check for empty file as that would cause a false "success" |
| 81 | if len(fileBytes) == 0 { |
| 82 | err := fmt.Errorf("file %s is empty", fileName) |
| 83 | return "", err |
| 84 | } |
| 85 | log.Debugf("Loaded %s", fileName) |
| 86 | return string(fileBytes), nil |
| 87 | } |