From fa91a58bf23b69a63147ab7e5918579f912362f8 Mon Sep 17 00:00:00 2001 From: Bernhard B Date: Thu, 19 Oct 2023 20:19:16 +0200 Subject: [PATCH] fixed bug in response parsing * strip info and warn messages from output --- src/client/cli.go | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/client/cli.go b/src/client/cli.go index 2cf35e9b..e6d36e1f 100644 --- a/src/client/cli.go +++ b/src/client/cli.go @@ -23,6 +23,32 @@ func NewCliClient(signalCliMode SignalCliMode, signalCliApiConfig *utils.SignalC } } +func stripInfoAndWarnMessages(input string) (string, string, string) { + output := "" + infoMessages := "" + warnMessages := "" + lines := strings.Split(input, "\n") + for _, line := range lines { + if strings.HasPrefix(line, "INFO") { + if infoMessages != "" { + infoMessages += "\n" + } + infoMessages += line + } else if strings.HasPrefix(line, "WARN") { + if warnMessages != "" { + warnMessages += "\n" + } + warnMessages += line + } else { + if output != "" { + output += "\n" + } + output += line + } + } + return output, infoMessages, warnMessages +} + func (s *CliClient) Execute(wait bool, args []string, stdin string) (string, error) { containerId, err := getContainerId() @@ -116,7 +142,20 @@ func (s *CliClient) Execute(wait bool, args []string, stdin string) (string, err combinedOutput := stdoutBuffer.String() + stderrBuffer.String() log.Debug("signal-cli output (stdout): ", stdoutBuffer.String()) log.Debug("signal-cli output (stderr): ", stderrBuffer.String()) - return combinedOutput, nil + strippedOutput, infoMessages, warnMessages := stripInfoAndWarnMessages(combinedOutput) + for _, line := range strings.Split(infoMessages, "\n") { + if line != "" { + log.Info(line) + } + } + + for _, line := range strings.Split(warnMessages, "\n") { + if line != "" { + log.Warn(line) + } + } + + return strippedOutput, nil } else { stdout, err := cmd.StdoutPipe() if err != nil {