Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip warnings in web index #455

Merged
merged 2 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
6 changes: 5 additions & 1 deletion pkg/grizzly/tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ 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": IsWarning,
},
)
_, err = t.Parse(string(contents))

return err
Expand Down
Loading