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

Commit f3bee1f

Browse files
committed
fixing spacing, error messages
1 parent bea5a17 commit f3bee1f

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

cmd/diff.go

+4
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ func diffFile(image1, image2 *pkgutil.Image) error {
163163
return err
164164
}
165165
util.TemplateOutput(writer, diff, "FilenameDiff")
166+
if err != nil {
167+
logrus.Error(err)
168+
return err
169+
}
166170
return nil
167171
}
168172

cmd/root.go

+3-11
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ Tarballs can also be specified by simply providing the path to the .tar, .tar.gz
7373
}
7474

7575
func outputResults(resultMap map[string]util.Result) {
76-
7776
// Outputs diff/analysis results in alphabetical order by analyzer name
7877
sortedTypes := []string{}
7978
for analyzerType := range resultMap {
@@ -84,7 +83,7 @@ func outputResults(resultMap map[string]util.Result) {
8483
// Get the writer
8584
writer, err := getWriter(outputFile)
8685
if err != nil {
87-
logrus.Error(err)
86+
errors.Wrap(err, "getting writer for output file")
8887
}
8988

9089
results := make([]interface{}, len(resultMap))
@@ -100,7 +99,6 @@ func outputResults(resultMap map[string]util.Result) {
10099
}
101100
}
102101
if json {
103-
104102
err := util.JSONify(writer, results)
105103
if err != nil {
106104
logrus.Error(err)
@@ -176,20 +174,14 @@ func getCacheDir(imageName string) (string, error) {
176174
func getWriter(outputFile string) (io.Writer, error) {
177175
var err error
178176
var outWriter io.Writer
179-
180177
// If the user specifies an output file, ensure exists
181178
if outputFile != "" {
182-
183179
// Don't overwrite a file that exists, unless given --force
184-
if _, err := os.Stat(outputFile); !os.IsNotExist(err) {
185-
if !forceWrite {
186-
logrus.Error("file exist, will not overwrite.")
187-
}
180+
if _, err := os.Stat(outputFile); !os.IsNotExist(err) && !forceWrite {
181+
errors.Wrap(err, "file exist, will not overwrite.")
188182
}
189-
190183
// Otherwise, output file is an io.writer
191184
outWriter, err = os.Create(outputFile)
192-
193185
}
194186
// If still doesn't exist, return stdout as the io.Writer
195187
if outputFile == "" {

0 commit comments

Comments
 (0)