all repos — searchix @ 7f7515906b28675a38a9988eb25f9b5b527c9d95

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

feat: improve logging of errors in source ID handler

Alan Pearce
commit

7f7515906b28675a38a9988eb25f9b5b527c9d95

parent

075a0a4a8bfd3dba66a5fbbf88b29d525c35c8be

3 files changed, 33 insertions(+), 1 deletion(-)

changed files
M internal/index/search.gointernal/index/search.go
@@ -2,6 +2,7 @@ package index
import ( "context" + "errors" "iter" "strings" "time"
@@ -15,6 +16,7 @@
"github.com/Southclaws/fault" "github.com/Southclaws/fault/fctx" "github.com/Southclaws/fault/fmsg" + "github.com/asdine/storm/v3" "github.com/blevesearch/bleve/v2" "github.com/blevesearch/bleve/v2/search" "github.com/blevesearch/bleve/v2/search/query"
@@ -124,7 +126,11 @@ }
doc, err := index.store.GetDocument(src, id) if err != nil { - index.log.Warn("error getting document", "error", err) + if errors.Is(err, storm.ErrNotFound) { + index.log.Warn("document not found", "source", sourceName, "id", id) + } else { + index.log.Error("error getting document", "error", err) + } continue }
M internal/server/mux.gointernal/server/mux.go
@@ -26,6 +26,7 @@ "alin.ovh/x/log"
"github.com/Southclaws/fault" "github.com/Southclaws/fault/fctx" "github.com/Southclaws/fault/fmsg" + "github.com/Southclaws/fault/ftag" "github.com/osdevisnot/sorvor/pkg/livereload" )
@@ -234,6 +235,22 @@ importerSingular := importerType.Singular()
doc, err := store.GetDocument(source, r.PathValue("id")) if err != nil { + if ftag.Get(err) == ftag.NotFound { + log.Warn("document not found", "source", source.Key, "id", r.PathValue("id")) + errorHandler(w, r, http.StatusText(http.StatusNotFound), http.StatusNotFound) + + return + } + + log.Error( + "failed to get document", + "source", + source.Key, + "id", + r.PathValue("id"), + "error", + err, + ) errorHandler( w, r,
M internal/storage/store.gointernal/storage/store.go
@@ -8,6 +8,7 @@
"alin.ovh/x/log" "github.com/Southclaws/fault" "github.com/Southclaws/fault/fmsg" + "github.com/Southclaws/fault/ftag" "github.com/asdine/storm/v3" "github.com/asdine/storm/v3/codec/gob" "go.etcd.io/bbolt"
@@ -197,6 +198,14 @@ return nil, fault.New("invalid importer type")
} if err != nil { + if errors.Is(err, storm.ErrNotFound) { + return nil, + fault.Wrap( + fault.Newf("document not found source: %s id: %s", source.Key, id), + ftag.With(ftag.NotFound), + ) + } + return nil, fault.Wrap( err, fmsg.Withf("failed to get document source: %s id: %s", source.Key, id),