Skip to content

Commit 7c01b45

Browse files
authored
Merge pull request #114 from nilslice/pr-113
plugins: error should include output
2 parents a1aae3b + 9de4a7b commit 7c01b45

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

.circleci/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ jobs:
4949
set +o pipefail
5050
5151
ERRS=$(protolock status --plugins=plugin-sample-error,plugin-sample-error | grep "some error" | wc -l)
52-
if [ "$ERRS" != 2 ]; then
52+
if [ "$ERRS" != 4 ]; then # (4 = 2 * 2, since errors are now reported using 2 lines)
5353
exit 1
5454
fi
5555
MOREERRS=$(protolock status --plugins=plugin-sample-error,plugin-sample-error,plugin-sample-error | grep "some error" | wc -l)
56-
if [ "$MOREERRS" != 3 ]; then
56+
if [ "$MOREERRS" != 6 ]; then # (6 = 3 * 2, since errors are now reported using 2 lines)
5757
exit 1
5858
fi
5959
- run:

cmd/protolock/plugins.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ func runPlugins(pluginList string, report *protolock.Report) (*protolock.Report,
8080
}
8181

8282
// execute the plugin and capture the output
83-
output, err := plugin.Output()
83+
output, err := plugin.CombinedOutput()
8484
if err != nil {
85-
pluginErrsChan <- wrapPluginErr(name, path, err)
85+
pluginErrsChan <- wrapPluginErr(name, path, err, output)
8686
return
8787
}
8888

@@ -101,7 +101,7 @@ func runPlugins(pluginList string, report *protolock.Report) (*protolock.Report,
101101

102102
if pluginData.PluginErrorMessage != "" {
103103
pluginErrsChan <- wrapPluginErr(
104-
name, path, errors.New(pluginData.PluginErrorMessage),
104+
name, path, errors.New(pluginData.PluginErrorMessage), output,
105105
)
106106
}
107107
}(name)
@@ -126,6 +126,9 @@ func runPlugins(pluginList string, report *protolock.Report) (*protolock.Report,
126126
return report, nil
127127
}
128128

129-
func wrapPluginErr(name, path string, err error) error {
130-
return fmt.Errorf("%s: %v (%s)", name, err, path)
129+
func wrapPluginErr(name, path string, err error, output []byte) error {
130+
out := strings.ReplaceAll(
131+
string(output), protolock.ProtoSep, protolock.FileSep,
132+
)
133+
return fmt.Errorf("%s (%s): %v\n%s", name, path, err, out)
131134
}

protopath.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ import (
66
)
77

88
const (
9-
filesep = string(filepath.Separator)
10-
protosep = ":/:"
9+
// FileSep is the string representation of the OS-specific path separator.
10+
FileSep = string(filepath.Separator)
11+
12+
// ProtoSep is an OS-ambiguous path separator to encode into the proto.lock
13+
// file. Use OsPath and ProtoPath funcs to convert.
14+
ProtoSep = ":/:"
1115
)
1216

1317
// Protopath is a type to assist in OS filepath transformations
@@ -16,14 +20,14 @@ type Protopath string
1620
// OSPath converts a path in the Protopath format to the OS path format
1721
func OSPath(ProtoPath Protopath) Protopath {
1822
return Protopath(
19-
strings.Replace(string(ProtoPath), protosep, filesep, -1),
23+
strings.Replace(string(ProtoPath), ProtoSep, FileSep, -1),
2024
)
2125
}
2226

2327
// ProtoPath converts a path in the OS path format to Protopath format
2428
func ProtoPath(OSPath Protopath) Protopath {
2529
return Protopath(
26-
strings.Replace(string(OSPath), filesep, protosep, -1),
30+
strings.Replace(string(OSPath), FileSep, ProtoSep, -1),
2731
)
2832
}
2933

0 commit comments

Comments
 (0)