From c78f9007c27fa717a1157cb262b5b2654a6d0dae Mon Sep 17 00:00:00 2001 From: wallrony Date: Mon, 1 Nov 2021 15:04:27 -0300 Subject: [PATCH] Fix error handling inside pandocPandoc func (#100) Other changes: - Updated strongdm/pandoc image references to edge Co-authored-by: vassalo --- Dockerfile | 2 +- Makefile | 4 ++-- internal/cli/app.go | 4 ++-- internal/render/pandoc.go | 13 ++++++------- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index 337b754..5560f72 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM strongdm/pandoc:latest +FROM strongdm/pandoc:edge # based on implementation by James Gregory MAINTAINER Comply diff --git a/Makefile b/Makefile index 9a247f6..1b8754c 100644 --- a/Makefile +++ b/Makefile @@ -52,8 +52,8 @@ else endif docker: - cd build && docker build -t strongdm/pandoc . - docker push strongdm/pandoc + cd build && docker build -t strongdm/pandoc:edge . + docker push strongdm/pandoc:edge cleanse: git checkout --orphan newbranch diff --git a/internal/cli/app.go b/internal/cli/app.go index 37e424b..d57a542 100644 --- a/internal/cli/app.go +++ b/internal/cli/app.go @@ -274,7 +274,7 @@ var pandocImageExists = func(ctx context.Context) bool { return false } for _, image := range imageList { - if strings.Contains(image.RepoTags[0], "strongdm/pandoc") { + if strings.Contains(image.RepoTags[0], "strongdm/pandoc:edge") { return true } } @@ -352,7 +352,7 @@ func cleanContainers(c *cli.Context) error { for _, c := range containers { // assume this container was leftover from previous aborted run - if strings.HasPrefix(c.Image, "strongdm/pandoc") { + if strings.HasPrefix(c.Image, "strongdm/pandoc:edge") { d := time.Second * 2 err = cli.ContainerStop(ctx, c.ID, &d) if err != nil { diff --git a/internal/render/pandoc.go b/internal/render/pandoc.go index ad8def0..a338074 100644 --- a/internal/render/pandoc.go +++ b/internal/render/pandoc.go @@ -18,10 +18,7 @@ var pandocArgs = []string{"-f", "markdown+smart", "--toc", "-N", "--template", " func pandoc(outputFilename string, errOutputCh chan error) { if config.WhichPandoc() == config.UsePandoc { - err := pandocPandoc(outputFilename) - if err != nil { - errOutputCh <- err - } + pandocPandoc(outputFilename, errOutputCh) } else { dockerPandoc(outputFilename, errOutputCh) } @@ -47,7 +44,7 @@ func dockerPandoc(outputFilename string, errOutputCh chan error) { } resp, err := cli.ContainerCreate(ctx, &container.Config{ - Image: "strongdm/pandoc", + Image: "strongdm/pandoc:edge", Cmd: pandocCmd}, hc, nil, nil, "") @@ -95,12 +92,14 @@ func dockerPandoc(outputFilename string, errOutputCh chan error) { } // 🐼 -func pandocPandoc(outputFilename string) error { +func pandocPandoc(outputFilename string, errOutputCh chan error) error { cmd := exec.Command("pandoc", append(pandocArgs, fmt.Sprintf("output/%s", outputFilename), fmt.Sprintf("output/%s.md", outputFilename))...) outputRaw, err := cmd.CombinedOutput() if err != nil { fmt.Println(string(outputRaw)) - return errors.Wrap(err, "error calling pandoc") + errOutputCh <- errors.Wrap(err, "error calling pandoc") + } else { + errOutputCh <- nil } return nil }