From 4819ef6d191474d87f668d129a71cb38d058091f Mon Sep 17 00:00:00 2001 From: Chao-Han Tsai Date: Tue, 9 Jul 2019 11:59:27 -0700 Subject: [PATCH 1/4] Plugin error should include output --- cmd/protolock/plugins.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/protolock/plugins.go b/cmd/protolock/plugins.go index e54b421..c05c665 100644 --- a/cmd/protolock/plugins.go +++ b/cmd/protolock/plugins.go @@ -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 } @@ -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) @@ -126,6 +126,6 @@ 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 { + return fmt.Errorf("%s: %v (%s) %s", name, err, path, string(output)) } From e8f27c521d87d2a87403c27b9c9e25904f4c6fbc Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Thu, 11 Jul 2019 15:23:31 -0600 Subject: [PATCH 2/4] path: export path separator consts to be useful outside package --- protopath.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/protopath.go b/protopath.go index 73b7369..78a9474 100644 --- a/protopath.go +++ b/protopath.go @@ -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 @@ -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), ) } From c2088219ad02db3ba72f9a26636b09cb793a3acb Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Thu, 11 Jul 2019 15:24:37 -0600 Subject: [PATCH 3/4] plugins: split combined error report into 2 lines for easier parsing, replace path seps --- cmd/protolock/plugins.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmd/protolock/plugins.go b/cmd/protolock/plugins.go index c05c665..0286857 100644 --- a/cmd/protolock/plugins.go +++ b/cmd/protolock/plugins.go @@ -127,5 +127,8 @@ func runPlugins(pluginList string, report *protolock.Report) (*protolock.Report, } func wrapPluginErr(name, path string, err error, output []byte) error { - return fmt.Errorf("%s: %v (%s) %s", name, err, path, string(output)) + out := strings.ReplaceAll( + string(output), protolock.ProtoSep, protolock.FileSep, + ) + return fmt.Errorf("%s (%s): %v\n%s", name, path, err, out) } From 9de4a7b5666c3bf2cb9fbdb8d30505e17e612920 Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Thu, 11 Jul 2019 15:25:28 -0600 Subject: [PATCH 4/4] ci: update config to support 2-line error report in evaluation of output --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 0ea5995..1a23b54 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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: