summaryrefslogtreecommitdiff
path: root/internal/processor/processor.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-04-10 09:48:07 +0300
committerPaul Buetow <paul@buetow.org>2026-04-10 09:48:07 +0300
commit4ff456a6111d8553893308a84e9f0e992d4809bf (patch)
treeddde0aa190b8dcbf6eb6649a82db732f0cdfd6a7 /internal/processor/processor.go
parentc8e10b6c5ab26d8bd34c288a7ce91c320862b58e (diff)
processor: return error when markdown pre-scan cannot read .md
claimedByMarkdown now wraps os.ReadFile failures instead of skipping, so Run fails fast and avoids wrong image claim state. Add regression test using an unreadable markdown file (Unix). Made-with: Cursor
Diffstat (limited to 'internal/processor/processor.go')
-rw-r--r--internal/processor/processor.go11
1 files changed, 7 insertions, 4 deletions
diff --git a/internal/processor/processor.go b/internal/processor/processor.go
index 2e2d626..b6fa40b 100644
--- a/internal/processor/processor.go
+++ b/internal/processor/processor.go
@@ -33,7 +33,10 @@ func Run(cfg *config.Config) (int, error) {
// Pre-scan markdown files to discover which image filenames they claim.
// Claimed images are excluded from independent processing.
- claimed := claimedByMarkdown(entries, cfg.InputDir)
+ claimed, err := claimedByMarkdown(entries, cfg.InputDir)
+ if err != nil {
+ return 0, err
+ }
count := 0
@@ -59,7 +62,7 @@ func Run(cfg *config.Config) (int, error) {
// claimedByMarkdown scans all .md entries in inputDir and returns a set of
// image filenames that are referenced within those markdown files.
// Those images should be embedded in the markdown post, not processed alone.
-func claimedByMarkdown(entries []os.DirEntry, inputDir string) map[string]bool {
+func claimedByMarkdown(entries []os.DirEntry, inputDir string) (map[string]bool, error) {
claimed := make(map[string]bool)
for _, entry := range entries {
@@ -70,7 +73,7 @@ func claimedByMarkdown(entries []os.DirEntry, inputDir string) map[string]bool {
mdPath := filepath.Join(inputDir, entry.Name())
data, err := os.ReadFile(mdPath)
if err != nil {
- continue
+ return nil, fmt.Errorf("read markdown for image claims %s: %w", entry.Name(), err)
}
for _, imgName := range findLocalImages(string(data), inputDir) {
@@ -78,7 +81,7 @@ func claimedByMarkdown(entries []os.DirEntry, inputDir string) map[string]bool {
}
}
- return claimed
+ return claimed, nil
}
// processFile processes a single input file into a new post directory.