Tweak scraper script error printing (#1107)

This commit is contained in:
bnkai 2021-02-09 10:07:53 +02:00 committed by GitHub
parent 714ae541d4
commit 984a0c9247
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 6 deletions

View File

@ -1,10 +1,10 @@
package scraper package scraper
import ( import (
"bufio"
"encoding/json" "encoding/json"
"errors" "errors"
"io" "io"
"io/ioutil"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"strings" "strings"
@ -59,6 +59,15 @@ func (s *scriptScraper) runScraperScript(inString string, out interface{}) error
return errors.New("Error running scraper script") return errors.New("Error running scraper script")
} }
scanner := bufio.NewScanner(stderr)
go func() { // log errors from stderr pipe
for scanner.Scan() {
logger.Errorf("scraper: %s", scanner.Text())
}
}()
logger.Debugf("Scraper script <%s> started", strings.Join(cmd.Args, " "))
// TODO - add a timeout here // TODO - add a timeout here
decodeErr := json.NewDecoder(stdout).Decode(out) decodeErr := json.NewDecoder(stdout).Decode(out)
if decodeErr != nil { if decodeErr != nil {
@ -66,14 +75,10 @@ func (s *scriptScraper) runScraperScript(inString string, out interface{}) error
return errors.New("could not unmarshal json: " + decodeErr.Error()) return errors.New("could not unmarshal json: " + decodeErr.Error())
} }
stderrData, _ := ioutil.ReadAll(stderr)
stderrString := string(stderrData)
err = cmd.Wait() err = cmd.Wait()
logger.Debugf("Scraper script finished")
if err != nil { if err != nil {
// error message should be in the stderr stream
logger.Errorf("scraper error when running command <%s>: %s", strings.Join(cmd.Args, " "), stderrString)
return errors.New("Error running scraper script") return errors.New("Error running scraper script")
} }