mirror of
https://github.com/rocky-linux/srpmproc.git
synced 2024-12-27 04:20:54 +00:00
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`.
This commit is contained in:
parent
c0794a01b1
commit
43e56cc58a
2 changed files with 4 additions and 8 deletions
|
@ -34,10 +34,12 @@ import (
|
|||
func patch(cfg *srpmprocpb.Cfg, pd *data.ProcessData, _ *data.ModeData, patchTree *git.Worktree, pushTree *git.Worktree) error {
|
||||
for _, patch := range cfg.Patch {
|
||||
patchFile, err := patchTree.Filesystem.Open(patch.File)
|
||||
pd.Log.Printf("[directives.patch] Parsing File: %s", patchFile.Name())
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf("COULD_NOT_OPEN_PATCH_FILE:%s", patch.File))
|
||||
}
|
||||
files, _, err := gitdiff.Parse(patchFile)
|
||||
|
||||
if err != nil {
|
||||
pd.Log.Printf("could not parse patch file: %v", err)
|
||||
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
|
|||
|
||||
err = gitdiff.Apply(&output, patchSubjectFile, patchedFile)
|
||||
if err != nil {
|
||||
pd.Log.Printf("could not apply patch: %v", err)
|
||||
pd.Log.Printf("[directives.patch] could not apply patch: \"%v\" on \"%s\" from \"%s\"", err, srcPath, patchSubjectFile.Name())
|
||||
return errors.New(fmt.Sprintf("COULD_NOT_APPLY_PATCH_WITH_SUBJECT:%s", srcPath))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,11 +21,9 @@
|
|||
package srpmproc
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -87,11 +85,7 @@ func cfgPatches(pd *data.ProcessData, md *data.ModeData, patchTree *git.Worktree
|
|||
|
||||
errs := directives.Apply(&cfg, pd, md, patchTree, pushTree)
|
||||
if errs != nil {
|
||||
err := json.NewEncoder(os.Stdout).Encode(errs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("errors: %v\n", errs)
|
||||
return fmt.Errorf("directives could not be applied")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue