Skip to content

Commit

Permalink
Merge pull request #114 from nilslice/pr-113
Browse files Browse the repository at this point in the history
plugins: error should include output
  • Loading branch information
nilslice authored Jul 14, 2019
2 parents a1aae3b + 9de4a7b commit 7c01b45
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ jobs:
set +o pipefail
ERRS=$(protolock status --plugins=plugin-sample-error,plugin-sample-error | grep "some error" | wc -l)
if [ "$ERRS" != 2 ]; then
if [ "$ERRS" != 4 ]; then # (4 = 2 * 2, since errors are now reported using 2 lines)
exit 1
fi
MOREERRS=$(protolock status --plugins=plugin-sample-error,plugin-sample-error,plugin-sample-error | grep "some error" | wc -l)
if [ "$MOREERRS" != 3 ]; then
if [ "$MOREERRS" != 6 ]; then # (6 = 3 * 2, since errors are now reported using 2 lines)
exit 1
fi
- run:
Expand Down
13 changes: 8 additions & 5 deletions cmd/protolock/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ func runPlugins(pluginList string, report *protolock.Report) (*protolock.Report,
}

// execute the plugin and capture the output
output, err := plugin.Output()
output, err := plugin.CombinedOutput()
if err != nil {
pluginErrsChan <- wrapPluginErr(name, path, err)
pluginErrsChan <- wrapPluginErr(name, path, err, output)
return
}

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

if pluginData.PluginErrorMessage != "" {
pluginErrsChan <- wrapPluginErr(
name, path, errors.New(pluginData.PluginErrorMessage),
name, path, errors.New(pluginData.PluginErrorMessage), output,
)
}
}(name)
Expand All @@ -126,6 +126,9 @@ func runPlugins(pluginList string, report *protolock.Report) (*protolock.Report,
return report, nil
}

func wrapPluginErr(name, path string, err error) error {
return fmt.Errorf("%s: %v (%s)", name, err, path)
func wrapPluginErr(name, path string, err error, output []byte) error {
out := strings.ReplaceAll(
string(output), protolock.ProtoSep, protolock.FileSep,
)
return fmt.Errorf("%s (%s): %v\n%s", name, path, err, out)
}
12 changes: 8 additions & 4 deletions protopath.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ import (
)

const (
filesep = string(filepath.Separator)
protosep = ":/:"
// FileSep is the string representation of the OS-specific path separator.
FileSep = string(filepath.Separator)

// ProtoSep is an OS-ambiguous path separator to encode into the proto.lock
// file. Use OsPath and ProtoPath funcs to convert.
ProtoSep = ":/:"
)

// Protopath is a type to assist in OS filepath transformations
Expand All @@ -16,14 +20,14 @@ type Protopath string
// OSPath converts a path in the Protopath format to the OS path format
func OSPath(ProtoPath Protopath) Protopath {
return Protopath(
strings.Replace(string(ProtoPath), protosep, filesep, -1),
strings.Replace(string(ProtoPath), ProtoSep, FileSep, -1),
)
}

// ProtoPath converts a path in the OS path format to Protopath format
func ProtoPath(OSPath Protopath) Protopath {
return Protopath(
strings.Replace(string(OSPath), filesep, protosep, -1),
strings.Replace(string(OSPath), FileSep, ProtoSep, -1),
)
}

Expand Down

0 comments on commit 7c01b45

Please sign in to comment.