Allow getJSON errors to be ignored

This change is mostly motivated to get a more stable CI build (we're building the Hugo site there, with Instagram and Twitter shortcodes sometimes failing).

Fixes #7866
This commit is contained in:
Bjørn Erik Pedersen
2020-10-21 11:17:48 +02:00
parent 8cbe2bbfad
commit fdfa4a5fe6
52 changed files with 318 additions and 221 deletions

View File

@@ -82,7 +82,7 @@ func (a *asciidocConverter) Supports(_ identity.Identity) bool {
func (a *asciidocConverter) getAsciidocContent(src []byte, ctx converter.DocumentContext) []byte {
path := getAsciidoctorExecPath()
if path == "" {
a.cfg.Logger.ERROR.Println("asciidoctor not found in $PATH: Please install.\n",
a.cfg.Logger.Errorln("asciidoctor not found in $PATH: Please install.\n",
" Leaving AsciiDoc content unrendered.")
return src
}
@@ -90,7 +90,7 @@ func (a *asciidocConverter) getAsciidocContent(src []byte, ctx converter.Documen
args := a.parseArgs(ctx)
args = append(args, "-")
a.cfg.Logger.INFO.Println("Rendering", ctx.DocumentName, "with", path, "using asciidoctor args", args, "...")
a.cfg.Logger.Infoln("Rendering", ctx.DocumentName, "with", path, "using asciidoctor args", args, "...")
return internal.ExternallyRenderContent(a.cfg, ctx, src, path, args)
}
@@ -103,7 +103,7 @@ func (a *asciidocConverter) parseArgs(ctx converter.DocumentContext) []string {
for _, extension := range cfg.Extensions {
if !asciidocext_config.AllowedExtensions[extension] {
a.cfg.Logger.ERROR.Println("Unsupported asciidoctor extension was passed in. Extension `" + extension + "` ignored.")
a.cfg.Logger.Errorln("Unsupported asciidoctor extension was passed in. Extension `" + extension + "` ignored.")
continue
}
@@ -112,7 +112,7 @@ func (a *asciidocConverter) parseArgs(ctx converter.DocumentContext) []string {
for attributeKey, attributeValue := range cfg.Attributes {
if asciidocext_config.DisallowedAttributes[attributeKey] {
a.cfg.Logger.ERROR.Println("Unsupported asciidoctor attribute was passed in. Attribute `" + attributeKey + "` ignored.")
a.cfg.Logger.Errorln("Unsupported asciidoctor attribute was passed in. Attribute `" + attributeKey + "` ignored.")
continue
}
@@ -125,7 +125,7 @@ func (a *asciidocConverter) parseArgs(ctx converter.DocumentContext) []string {
destinationDir := a.cfg.Cfg.GetString("destination")
if destinationDir == "" {
a.cfg.Logger.ERROR.Println("markup.asciidocext.workingFolderCurrent requires hugo command option --destination to be set")
a.cfg.Logger.Errorln("markup.asciidocext.workingFolderCurrent requires hugo command option --destination to be set")
}
if !filepath.IsAbs(destinationDir) && sourceDir != "" {
destinationDir = filepath.Join(sourceDir, destinationDir)
@@ -144,14 +144,14 @@ func (a *asciidocConverter) parseArgs(ctx converter.DocumentContext) []string {
if ok {
postDir = filepath.Base(page.RelPermalink())
} else {
a.cfg.Logger.ERROR.Println("unable to cast interface to pageSubset")
a.cfg.Logger.Errorln("unable to cast interface to pageSubset")
}
outDir, err = filepath.Abs(filepath.Join(destinationDir, filepath.Dir(ctx.DocumentName), postDir))
}
if err != nil {
a.cfg.Logger.ERROR.Println("asciidoctor outDir: ", err)
a.cfg.Logger.Errorln("asciidoctor outDir: ", err)
}
args = append(args, "--base-dir", contentDir, "-a", "outdir="+outDir)
@@ -160,7 +160,7 @@ func (a *asciidocConverter) parseArgs(ctx converter.DocumentContext) []string {
if cfg.NoHeaderOrFooter {
args = append(args, "--no-header-footer")
} else {
a.cfg.Logger.WARN.Println("asciidoctor parameter NoHeaderOrFooter is expected for correct html rendering")
a.cfg.Logger.Warnln("asciidoctor parameter NoHeaderOrFooter is expected for correct html rendering")
}
if cfg.SectionNumbers {
@@ -187,7 +187,7 @@ func (a *asciidocConverter) appendArg(args []string, option, value, defaultValue
if allowedValues[value] {
args = append(args, option, value)
} else {
a.cfg.Logger.ERROR.Println("Unsupported asciidoctor value `" + value + "` for option " + option + " was passed in and will be ignored.")
a.cfg.Logger.Errorln("Unsupported asciidoctor value `" + value + "` for option " + option + " was passed in and will be ignored.")
}
}
return args

View File

@@ -31,7 +31,7 @@ type ProviderConfig struct {
Cfg config.Provider // Site config
ContentFs afero.Fs
Logger *loggers.Logger
Logger loggers.Logger
Highlight func(code, lang, optsStr string) (string, error)
}

View File

@@ -25,11 +25,11 @@ func ExternallyRenderContent(
for _, item := range strings.Split(cmderr.String(), "\n") {
item := strings.TrimSpace(item)
if item != "" {
logger.ERROR.Printf("%s: %s", ctx.DocumentName, item)
logger.Errorf("%s: %s", ctx.DocumentName, item)
}
}
if err != nil {
logger.ERROR.Printf("%s rendering %s: %v", path, ctx.DocumentName, err)
logger.Errorf("%s rendering %s: %v", path, ctx.DocumentName, err)
}
return normalizeExternalHelperLineFeeds(out.Bytes())

View File

@@ -47,7 +47,7 @@ type orgConverter struct {
func (c *orgConverter) Convert(ctx converter.RenderContext) (converter.Result, error) {
logger := c.cfg.Logger
config := org.New()
config.Log = logger.WARN
config.Log = logger.Warn()
config.ReadFile = func(filename string) ([]byte, error) {
return afero.ReadFile(c.cfg.ContentFs, filename)
}
@@ -55,7 +55,7 @@ func (c *orgConverter) Convert(ctx converter.RenderContext) (converter.Result, e
writer.HighlightCodeBlock = func(source, lang string, inline bool) string {
highlightedSource, err := c.cfg.Highlight(source, lang, "")
if err != nil {
logger.ERROR.Printf("Could not highlight source as lang %s. Using raw source.", lang)
logger.Errorf("Could not highlight source as lang %s. Using raw source.", lang)
return source
}
return highlightedSource
@@ -63,7 +63,7 @@ func (c *orgConverter) Convert(ctx converter.RenderContext) (converter.Result, e
html, err := config.Parse(bytes.NewReader(ctx.Src), c.ctx.DocumentName).Write(writer)
if err != nil {
logger.ERROR.Printf("Could not render org: %s. Using unrendered content.", err)
logger.Errorf("Could not render org: %s. Using unrendered content.", err)
return converter.Bytes(ctx.Src), nil
}
return converter.Bytes([]byte(html)), nil

View File

@@ -57,7 +57,7 @@ func (c *pandocConverter) getPandocContent(src []byte, ctx converter.DocumentCon
logger := c.cfg.Logger
path := getPandocExecPath()
if path == "" {
logger.ERROR.Println("pandoc not found in $PATH: Please install.\n",
logger.Println("pandoc not found in $PATH: Please install.\n",
" Leaving pandoc content unrendered.")
return src
}

View File

@@ -60,11 +60,11 @@ func (c *rstConverter) getRstContent(src []byte, ctx converter.DocumentContext)
path := getRstExecPath()
if path == "" {
logger.ERROR.Println("rst2html / rst2html.py not found in $PATH: Please install.\n",
logger.Println("rst2html / rst2html.py not found in $PATH: Please install.\n",
" Leaving reStructuredText content unrendered.")
return src
}
logger.INFO.Println("Rendering", ctx.DocumentName, "with", path, "...")
logger.Println("Rendering", ctx.DocumentName, "with", path, "...")
var result []byte
// certain *nix based OSs wrap executables in scripted launchers
// invoking binaries on these OSs via python interpreter causes SyntaxError