Skip to content
This repository was archived by the owner on Jun 27, 2025. It is now read-only.

Commit 43e56cc

Browse files
authored
Fixingup error returns for directives (#26)
The processing of pkg/directives/patch.go will return an error type but handeling of it was attempting to use JSON encoding to print to screen. There is no reason to use that since the `error` type only has a string in it but doesn't get marshalled properly to json due to the private variables. This is also the only time json marshaling is used so instead covert the error handling to just `fmt.Printf`.
1 parent c0794a0 commit 43e56cc

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

pkg/directives/patch.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@ import (
3434
func patch(cfg *srpmprocpb.Cfg, pd *data.ProcessData, _ *data.ModeData, patchTree *git.Worktree, pushTree *git.Worktree) error {
3535
for _, patch := range cfg.Patch {
3636
patchFile, err := patchTree.Filesystem.Open(patch.File)
37+
pd.Log.Printf("[directives.patch] Parsing File: %s", patchFile.Name())
3738
if err != nil {
3839
return errors.New(fmt.Sprintf("COULD_NOT_OPEN_PATCH_FILE:%s", patch.File))
3940
}
4041
files, _, err := gitdiff.Parse(patchFile)
42+
4143
if err != nil {
4244
pd.Log.Printf("could not parse patch file: %v", err)
4345
return errors.New(fmt.Sprintf("COULD_NOT_PARSE_PATCH_FILE:%s", patch.File))
@@ -57,7 +59,7 @@ func patch(cfg *srpmprocpb.Cfg, pd *data.ProcessData, _ *data.ModeData, patchTre
5759

5860
err = gitdiff.Apply(&output, patchSubjectFile, patchedFile)
5961
if err != nil {
60-
pd.Log.Printf("could not apply patch: %v", err)
62+
pd.Log.Printf("[directives.patch] could not apply patch: \"%v\" on \"%s\" from \"%s\"", err, srcPath, patchSubjectFile.Name())
6163
return errors.New(fmt.Sprintf("COULD_NOT_APPLY_PATCH_WITH_SUBJECT:%s", srcPath))
6264
}
6365
}

pkg/srpmproc/patch.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@
2121
package srpmproc
2222

2323
import (
24-
"encoding/json"
2524
"fmt"
2625
"io"
2726
"log"
28-
"os"
2927
"path/filepath"
3028
"strings"
3129
"time"
@@ -87,11 +85,7 @@ func cfgPatches(pd *data.ProcessData, md *data.ModeData, patchTree *git.Worktree
8785

8886
errs := directives.Apply(&cfg, pd, md, patchTree, pushTree)
8987
if errs != nil {
90-
err := json.NewEncoder(os.Stdout).Encode(errs)
91-
if err != nil {
92-
return err
93-
}
94-
88+
fmt.Printf("errors: %v\n", errs)
9589
return fmt.Errorf("directives could not be applied")
9690
}
9791
}

0 commit comments

Comments
 (0)