about summary refs log tree commit diff stats
path: root/internal/components
diff options
context:
space:
mode:
authorAlan Pearce2024-06-21 16:58:38 +0200
committerAlan Pearce2024-06-21 16:58:38 +0200
commitdbeddced4046cb5756af2604f5cb6734b3e7cee6 (patch)
treedcad7aa9201a6e5a8e97f3f88b7aeadb50c0c330 /internal/components
parent107d54a4c4a415f3581a452878cdd625f7f2634a (diff)
downloadsearchix-dbeddced4046cb5756af2604f5cb6734b3e7cee6.tar.lz
searchix-dbeddced4046cb5756af2604f5cb6734b3e7cee6.tar.zst
searchix-dbeddced4046cb5756af2604f5cb6734b3e7cee6.zip
fix: panic rendering results
Diffstat (limited to 'internal/components')
-rw-r--r--internal/components/options.templ4
-rw-r--r--internal/components/packages.templ4
-rw-r--r--internal/components/results.templ10
3 files changed, 16 insertions, 2 deletions
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) {
 		</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>
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) {
 		</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>
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 {