Skip to content

Commit 392d449

Browse files
committed
feat: better error handling
1 parent 93c8427 commit 392d449

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

autopdf

16.9 MB
Binary file not shown.

internal/tex/build.go

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"log"
66
"os"
77
"path/filepath"
8+
"strings"
89

910
"github.com/BuddhiLW/AutoPDF/configs"
1011
"github.com/BuddhiLW/AutoPDF/internal/converter"
@@ -133,21 +134,26 @@ If no configuration file is provided, it will look for autopdf.yaml in the curre
133134
}
134135

135136
// Ensure that the output file exists and isn't empty
136-
if cfg.Output != "" {
137-
// Check if output file exists
138-
fileInfo, err := os.Stat(cfg.Output.String())
139-
if err != nil {
140-
if os.IsNotExist(err) {
141-
log.Printf("Warning: Output file %s doesn't exist after compilation", cfg.Output.String())
142-
// Don't create an empty file here - that would hide the real issue
143-
} else {
144-
log.Printf("Error checking output file: %s", err)
137+
if cfg.Output != "" {
138+
// Check if output file exists - ensure we check with .pdf extension
139+
outputPath := cfg.Output.String()
140+
if !strings.HasSuffix(outputPath, ".pdf") {
141+
outputPath = outputPath + ".pdf"
145142
}
146-
} else if fileInfo.Size() == 0 {
147-
log.Printf("Warning: Output file %s exists but is empty", cfg.Output.String())
148-
}
149-
150-
// Use the provided output path
143+
144+
fileInfo, err := os.Stat(outputPath)
145+
if err != nil {
146+
if os.IsNotExist(err) {
147+
log.Printf("Warning: Output file %s doesn't exist after compilation", outputPath)
148+
// Don't create an empty file here - that would hide the real issue
149+
} else {
150+
log.Printf("Error checking output file: %s", err)
151+
}
152+
} else if fileInfo.Size() == 0 {
153+
log.Printf("Warning: Output file %s exists but is empty", outputPath)
154+
}
155+
156+
// Use the provided output path
151157
outputPDF = cfg.Output.String()
152158
}
153159
fmt.Printf("Successfully built PDF: %s\n", outputPDF)

test/model_letter/out/output.pdf

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)