Skip to content

Commit

Permalink
fix(tool): OpenMeteo - handle empty geocode result
Browse files Browse the repository at this point in the history
Ref: #36
  • Loading branch information
Tomas2D committed Sep 27, 2024
1 parent 699ccac commit 424e620
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/tools/weather/openMeteo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}
9 changes: 9 additions & 0 deletions tests/e2e/tools/openMeteo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.`);
});
});

0 comments on commit 424e620

Please sign in to comment.