fix(recipe): add error handling to unified patch creation
Handle potential errors from file writes in createUnifiedPatch to prevent silent failures.
This commit is contained in:
parent
0e234419f4
commit
1c79abce8d
@ -211,12 +211,23 @@ func createUnifiedPatch(changes []FileChange, patchPath string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
defer func(f *os.File) {
|
||||
err := f.Close()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}(f)
|
||||
|
||||
for _, ch := range changes {
|
||||
fmt.Fprintf(f, "--- %s\n+++ %s\n@@ -0,0 +1,%d @@\n", ch.File, ch.File, strings.Count(ch.Content, "\n")+1)
|
||||
_, err := fmt.Fprintf(f, "--- %s\n+++ %s\n@@ -0,0 +1,%d @@\n", ch.File, ch.File, strings.Count(ch.Content, "\n")+1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, line := range strings.Split(ch.Content, "\n") {
|
||||
fmt.Fprintf(f, "+%s\n", line)
|
||||
_, err := fmt.Fprintf(f, "+%s\n", line)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
Loading…
Reference in New Issue
Block a user