From 5692b4213aef64d1b25535878745c97a08d5a797 Mon Sep 17 00:00:00 2001 From: Malcolm Holmes Date: Mon, 17 Jun 2024 10:58:15 +0100 Subject: [PATCH 1/2] Skip warnings in web index --- .../embed/templates/proxy/index.html.tmpl | 3 ++- pkg/grizzly/errors.go | 17 +++++++++++++++++ pkg/grizzly/parsing.go | 2 +- pkg/grizzly/tmpl.go | 8 +++++++- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/pkg/grizzly/embed/templates/proxy/index.html.tmpl b/pkg/grizzly/embed/templates/proxy/index.html.tmpl index c83a6e75..641e48a7 100644 --- a/pkg/grizzly/embed/templates/proxy/index.html.tmpl +++ b/pkg/grizzly/embed/templates/proxy/index.html.tmpl @@ -8,16 +8,17 @@ {{ template "proxy/header.html.tmpl" . }} -
{{ if ne (len .ParseErrors) 0 }}

Errors

{{ range .ParseErrors }} + {{ if not (IsWarning .) }}
  • {{ . }}
  • + {{ end }} {{ end }} {{ end }}

    Available dashboards

    diff --git a/pkg/grizzly/errors.go b/pkg/grizzly/errors.go index bed533ff..ba2d3c4d 100644 --- a/pkg/grizzly/errors.go +++ b/pkg/grizzly/errors.go @@ -39,3 +39,20 @@ func NewUnrecognisedFormatError(file string) UnrecognisedFormatError { File: file, } } + +type Warning struct { + Err error +} + +func NewWarning(err error) Warning { + return Warning{err} +} + +func (w Warning) Error() string { + return w.Err.Error() +} + +func IsWarning(err any) bool { + _, ok := err.(Warning) + return ok +} diff --git a/pkg/grizzly/parsing.go b/pkg/grizzly/parsing.go index 2def807d..4b172501 100644 --- a/pkg/grizzly/parsing.go +++ b/pkg/grizzly/parsing.go @@ -161,7 +161,7 @@ func (parser *ChainParser) parseFile(file string, options ParserOptions) (Resour return resources, nil } - return Resources{}, NewUnrecognisedFormatError(file) + return Resources{}, NewWarning(NewUnrecognisedFormatError(file)) } func parseAny(registry Registry, data any, resourceKind, folderUID string, source Source) (Resources, error) { diff --git a/pkg/grizzly/tmpl.go b/pkg/grizzly/tmpl.go index e0722101..456e684e 100644 --- a/pkg/grizzly/tmpl.go +++ b/pkg/grizzly/tmpl.go @@ -44,7 +44,13 @@ func findAndParseTemplates(vfs fs.FS, rootTmpl *template.Template, rootDir strin } templateName := strings.TrimPrefix(strings.TrimPrefix(path, rootDir), "/") - t := rootTmpl.New(templateName) + t := rootTmpl.New(templateName).Funcs( + template.FuncMap{ + "IsWarning": func(i any) bool { + return IsWarning(i) + }, + }, + ) _, err = t.Parse(string(contents)) return err From 4539e152ed581ecee7233cbd82fdbe898766016c Mon Sep 17 00:00:00 2001 From: Malcolm Holmes Date: Mon, 17 Jun 2024 13:42:33 +0100 Subject: [PATCH 2/2] Lint --- pkg/grizzly/tmpl.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pkg/grizzly/tmpl.go b/pkg/grizzly/tmpl.go index 456e684e..b29ac838 100644 --- a/pkg/grizzly/tmpl.go +++ b/pkg/grizzly/tmpl.go @@ -46,9 +46,7 @@ func findAndParseTemplates(vfs fs.FS, rootTmpl *template.Template, rootDir strin templateName := strings.TrimPrefix(strings.TrimPrefix(path, rootDir), "/") t := rootTmpl.New(templateName).Funcs( template.FuncMap{ - "IsWarning": func(i any) bool { - return IsWarning(i) - }, + "IsWarning": IsWarning, }, ) _, err = t.Parse(string(contents))