Tweak scraper script error printing ()

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
pkg/scraper

View File

@ -1,10 +1,10 @@
package scraper
import (
"bufio"
"encoding/json"
"errors"
"io"
"io/ioutil"
"os/exec"
"path/filepath"
"strings"
@ -59,6 +59,15 @@ func (s *scriptScraper) runScraperScript(inString string, out interface{}) error
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
decodeErr := json.NewDecoder(stdout).Decode(out)
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())
}
stderrData, _ := ioutil.ReadAll(stderr)
stderrString := string(stderrData)
err = cmd.Wait()
logger.Debugf("Scraper script finished")
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")
}