Skip to content

Commit

Permalink
Fixingup error returns for directives (#26)
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
PlaidCat authored Jul 12, 2024
1 parent c0794a0 commit 43e56cc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
4 changes: 3 additions & 1 deletion pkg/directives/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))
}
}
Expand Down
8 changes: 1 addition & 7 deletions pkg/srpmproc/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@
package srpmproc

import (
"encoding/json"
"fmt"
"io"
"log"
"os"
"path/filepath"
"strings"
"time"
Expand Down Expand Up @@ -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")
}
}
Expand Down

0 comments on commit 43e56cc

Please sign in to comment.