From 424e620669fc06d256b9312cfd29e603afd7b98a Mon Sep 17 00:00:00 2001 From: Tomas Dvorak Date: Fri, 27 Sep 2024 13:43:02 +0200 Subject: [PATCH] fix(tool): OpenMeteo - handle empty geocode result Ref: #36 --- src/tools/weather/openMeteo.ts | 3 +++ tests/e2e/tools/openMeteo.test.ts | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/src/tools/weather/openMeteo.ts b/src/tools/weather/openMeteo.ts index 296d92b..95ad1eb 100644 --- a/src/tools/weather/openMeteo.ts +++ b/src/tools/weather/openMeteo.ts @@ -186,6 +186,9 @@ export class OpenMeteoTool extends Tool< } const { results } = await response.json(); + if (!results || results.length === 0) { + throw new ToolError(`Location '${location.name}' was not found.`); + } return results[0]; } } diff --git a/tests/e2e/tools/openMeteo.test.ts b/tests/e2e/tools/openMeteo.test.ts index b0c895e..923afe8 100644 --- a/tests/e2e/tools/openMeteo.test.ts +++ b/tests/e2e/tools/openMeteo.test.ts @@ -59,4 +59,13 @@ describe("OpenMeteo", () => { }), ).rejects.toThrowError(ToolInputValidationError); }); + + it("Throws for unknown location", async () => { + await expect( + instance.run({ + location: { name: "ABCDEFGH" }, + start_date: "2024-01-01", + }), + ).rejects.toThrowErrorMatchingInlineSnapshot(`ToolError: Location 'ABCDEFGH' was not found.`); + }); });