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:
Jonathan Maple 2024-07-12 11:04:42 -07:00 committed by GitHub
parent c0794a01b1
commit 43e56cc58a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 8 deletions

View file

@ -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))
}
}

View file

@ -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")
}
}