fix: panic rendering results
Alan Pearce alan@alanpearce.eu
Fri, 21 Jun 2024 16:58:38 +0200
3 files changed, 16 insertions(+), 2 deletions(-)
M internal/components/options.templ → internal/components/options.templ
@@ -15,7 +15,9 @@ </tr> </thead> <tbody> for _, hit := range result.Hits { - @optionRow(hit.Data.(nix.Option)) + if m := convertMatch[nix.Option](hit.Data); m != nil { + @optionRow(*m) + } } </tbody> </table>
M internal/components/packages.templ → internal/components/packages.templ
@@ -16,7 +16,9 @@ </tr> </thead> <tbody> for _, hit := range result.Hits { - @packageRow(hit.Data.(nix.Package)) + if m := convertMatch[nix.Package](hit.Data); m != nil { + @packageRow(*m) + } } </tbody> </table>
M internal/components/results.templ → internal/components/results.templ
@@ -2,8 +2,18 @@ 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 != "" {