summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-05-13 09:54:44 +0300
committerPaul Buetow <paul@buetow.org>2026-05-13 09:54:44 +0300
commit32a3fe61700884d7378858ba21a809c31a9fc5eb (patch)
treeafafa6791f1d76635f3f322ea1a2664beb7e6d70 /cmd
parent54afec7ab8fc2d23d0aa8e4469536a683779620f (diff)
replace panic with os.Exit and error log in cmd/filewriter
Panics in non-setup code violate the AGENTS.md convention. Replace all three panic(err) calls with fmt.Fprintf(os.Stderr, ...) + os.Exit(1) so the process exits cleanly with a human-readable message instead of a stack trace. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/filewriter/main.go10
1 files changed, 7 insertions, 3 deletions
diff --git a/cmd/filewriter/main.go b/cmd/filewriter/main.go
index 25f5cb7..b175371 100644
--- a/cmd/filewriter/main.go
+++ b/cmd/filewriter/main.go
@@ -1,6 +1,7 @@
package main
import (
+ "fmt"
"os"
"time"
)
@@ -9,7 +10,8 @@ func main() {
// Open the file in append mode, create it if it doesn't exist
file, err := os.OpenFile("output.txt", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
- panic(err)
+ fmt.Fprintf(os.Stderr, "filewriter: failed to open output file: %v\n", err)
+ os.Exit(1)
}
defer file.Close()
@@ -20,13 +22,15 @@ func main() {
for {
_, err := file.Write(data)
if err != nil {
- panic(err)
+ fmt.Fprintf(os.Stderr, "filewriter: failed to write data: %v\n", err)
+ os.Exit(1)
}
// Flush writes to stable storage
err = file.Sync()
if err != nil {
- panic(err)
+ fmt.Fprintf(os.Stderr, "filewriter: failed to sync file: %v\n", err)
+ os.Exit(1)
}
// Wait for 3 seconds