all repos — searchix @ 77a8dec1d8c80ff22bc539f7bd74bf20ad031353

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

feat: include search query in error messages

Alan Pearce
commit

77a8dec1d8c80ff22bc539f7bd74bf20ad031353

parent

ff56604e64988b29c6557f57ccf59284747843ec

1 file changed, 5 insertions(+), 2 deletions(-)

changed files
M internal/server/mux.gointernal/server/mux.go
@@ -24,6 +24,7 @@ "alin.ovh/searchix/internal/sentryhttp"
"alin.ovh/x/log" "github.com/Southclaws/fault" + "github.com/Southclaws/fault/fctx" "github.com/Southclaws/fault/fmsg" "github.com/osdevisnot/sorvor/pkg/livereload" )
@@ -98,6 +99,7 @@ }
if r.URL.Query().Has("query") { qs := r.URL.Query().Get("query") + ctx := fctx.WithMeta(r.Context(), "search_query", qs) if len(qs) < 2 { errorHandler(w, r, "Query too short", http.StatusBadRequest)
@@ -121,7 +123,7 @@ }
} page := pagination.New(pageNumber, pageSize) - ctx, cancel := context.WithTimeout(r.Context(), cfg.Web.SearchTimeout.Duration) + ctx, cancel := context.WithTimeout(ctx, cfg.Web.SearchTimeout.Duration) results, err := index.Search(ctx, source, qs, page.From, page.Size) cancel()
@@ -131,7 +133,8 @@ errorHandler(w, r, "Search timed out", http.StatusInternalServerError)
return } - log.Error("search error", "error", err) + meta := fctx.Unwrap(err) + log.Error("search error", "error", err, "search_query", meta["search_query"]) errorHandler(w, r, err.Error(), http.StatusInternalServerError) return