all repos — searchix @ dbeddced4046cb5756af2604f5cb6734b3e7cee6

Search engine for NixOS, nix-darwin, home-manager and NUR users

fix: panic rendering results
Alan Pearce alan@alanpearce.eu
Fri, 21 Jun 2024 16:58:38 +0200
commit

dbeddced4046cb5756af2604f5cb6734b3e7cee6

parent

107d54a4c4a415f3581a452878cdd625f7f2634a

M internal/components/options.templinternal/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.templinternal/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.templinternal/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 != "" {