Skip to content

Commit

Permalink
Skip warnings in web index
Browse files Browse the repository at this point in the history
  • Loading branch information
malcolmholmes committed Jun 17, 2024
1 parent 3c36e7e commit 5692b42
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
3 changes: 2 additions & 1 deletion pkg/grizzly/embed/templates/proxy/index.html.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@
<body dir="ltr">
{{ template "proxy/header.html.tmpl" . }}


<main>
<div>
{{ if ne (len .ParseErrors) 0 }}
<h1>Errors</h1>

{{ range .ParseErrors }}
{{ if not (IsWarning .) }}
<li>
<code>{{ . }}</code>
</li>
{{ end }}
{{ end }}
{{ end }}
<h1>Available dashboards</h1>
Expand Down
17 changes: 17 additions & 0 deletions pkg/grizzly/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion pkg/grizzly/parsing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 7 additions & 1 deletion pkg/grizzly/tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Check failure on line 49 in pkg/grizzly/tmpl.go

View workflow job for this annotation

GitHub Actions / lint

unlambda: replace `func(i any) bool {
return IsWarning(i)
},
},
)
_, err = t.Parse(string(contents))

return err
Expand Down

0 comments on commit 5692b42

Please sign in to comment.