Skip to content

Build your personal knowledge base with Trilium Notes

fix(search): offer no label values where looking them up fails

Elian Dorana5f41f08a366
diff --git a/apps/client/src/widgets/ribbon/search_completions.spec.ts b/apps/client/src/widgets/ribbon/search_completions.spec.ts
index 2139fb5843..9e089065dd 100644
--- a/apps/client/src/widgets/ribbon/search_completions.spec.ts
+++ b/apps/client/src/widgets/ribbon/search_completions.spec.ts
@@ -168,6 +168,12 @@ describe("searchCompletionAt", () => {
expect((await entryFor(result, "science fiction"))?.insert).toBe("\"science fiction\"");
});
+ it("offers no values where looking them up fails, rather than failing the list", async () => {
+ vi.mocked(server.get).mockRejectedValue(new Error("offline"));
+
+ expect(await entriesOf(complete("#genre = fic"))).toEqual([]);
+ });
+
it("quotes a value spelled like a reserved operand, whatever its case", async () => {
vi.mocked(server.get).mockResolvedValue([ "note", "Today", "monthly" ]);
diff --git a/apps/client/src/widgets/ribbon/search_completions.ts b/apps/client/src/widgets/ribbon/search_completions.ts
index c3d75c3baa..0e57af207c 100644
--- a/apps/client/src/widgets/ribbon/search_completions.ts
+++ b/apps/client/src/widgets/ribbon/search_completions.ts
@@ -288,7 +288,13 @@ function dateValues(): PropertyValue[] {
* is a note ID, and the endpoint behind this collects label values alone.
*/
async function labelValues(name: string, quote: string): Promise<SearchEntry[]> {
- const values = await server.get<string[]>(`attribute-values/${encodeURIComponent(name)}`);
+ let values: string[];
+ try {
+ values = await server.get<string[]>(`attribute-values/${encodeURIComponent(name)}`);
+ } catch {
+ // A failed lookup offers no values, and the query is typed as usual.
+ return [];
+ }
return values.map((value) => ({ id: value, title: value, icon: "bx bx-purchase-tag-alt", insert: applyValue(value, quote) }));
}