From dbeddced4046cb5756af2604f5cb6734b3e7cee6 Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Fri, 21 Jun 2024 16:58:38 +0200 Subject: fix: panic rendering results --- internal/components/options.templ | 4 +++- internal/components/packages.templ | 4 +++- internal/components/results.templ | 10 ++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) (limited to 'internal') diff --git a/internal/components/options.templ b/internal/components/options.templ index ce3ffff..44bc5a3 100644 --- a/internal/components/options.templ +++ b/internal/components/options.templ @@ -15,7 +15,9 @@ templ Options(result *index.Result) {
for _, hit := range result.Hits { - @optionRow(hit.Data.(nix.Option)) + if m := convertMatch[nix.Option](hit.Data); m != nil { + @optionRow(*m) + } } diff --git a/internal/components/packages.templ b/internal/components/packages.templ index 4e00a5a..e811220 100644 --- a/internal/components/packages.templ +++ b/internal/components/packages.templ @@ -16,7 +16,9 @@ templ Packages(result *index.Result) { for _, hit := range result.Hits { - @packageRow(hit.Data.(nix.Package)) + if m := convertMatch[nix.Package](hit.Data); m != nil { + @packageRow(*m) + } } diff --git a/internal/components/results.templ b/internal/components/results.templ index 3953cc3..95c5390 100644 --- a/internal/components/results.templ +++ b/internal/components/results.templ @@ -2,9 +2,19 @@ package components import ( "strconv" + "log/slog" "searchix/internal/nix" ) +func convertMatch[I nix.Importable](m nix.Importable) *I { + i, ok := m.(I) + if !ok { + slog.Warn("Converting match failed", "match", m) + return nil + } + return &i +} + templ Results(r ResultData) { if r.Query != "" { if r.Results != nil && r.Results.Total > 0 { -- cgit 1.4.1