Skip to content

Commit

Permalink
fix std exception
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacbrodsky committed Feb 21, 2024
1 parent 0e61395 commit 954e710
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions h3_functions/h3_regions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,13 @@ static size_t readNumber(const std::string &str, size_t offset, double &num) {
offset++;
}
std::string part = str.substr(start, offset - start);
num = std::stod(part);
return offset;

try {
num = std::stod(part);
return offset;
} catch (std::invalid_argument const& ex) {
throw InvalidInputException(StringUtil::Format("Invalid number around %lu, %lu", start, offset));
}
}

static size_t readGeoLoop(const std::string &str, size_t offset, duckdb::shared_ptr<std::vector<LatLng>> verts,
Expand Down
4 changes: 2 additions & 2 deletions test/sql/h3/h3_functions_regions.test
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ Expected ( at pos 9
statement error
select h3_polygon_wkt_to_cells('POLYGON ((xx-122.40898669969356 37.81331899988944, -122.38054369969613 37.78663019990699, -122.35447369969584 37.719806199904276, -122.51234369969448 37.70761319990403, -122.52471869969825 37.783587199903444, -122.47987669969707 37.81515719990604, -122.40898669969356 37.81331899988944), (-122.44711969969569 37.786980199908015, -122.45907769969834 37.76641019990431, -122.41370969969519 37.77106819990672)) ', 9);
----
Invalid Error: stod
Invalid Input Error: Invalid number around 10, 31

statement error
select h3_polygon_wkt_to_cells('POLYGON ((-122.40898669969356 37.81331899988944 xx, -122.38054369969613 37.78663019990699, -122.35447369969584 37.719806199904276, -122.51234369969448 37.70761319990403, -122.52471869969825 37.783587199903444, -122.47987669969707 37.81515719990604, -122.40898669969356 37.81331899988944), (-122.44711969969569 37.786980199908015, -122.45907769969834 37.76641019990431, -122.41370969969519 37.77106819990672)) ', 9);
----
Invalid Error: stod
Invalid Input Error: Invalid number around 48, 50

statement error
select h3_polygon_wkt_to_cells('POLYGON ((-122.40898669969356 37.81331899988944, -122.38054369969613 37.78663019990699, -122.35447369969584 37.719806199904276, -122.51234369969448 37.70761319990403, -122.52471869969825 37.783587199903444, -122.47987669969707 37.81515719990604, -122.40898669969356 37.81331899988944)xx, (-122.44711969969569 37.786980199908015, -122.45907769969834 37.76641019990431, -122.41370969969519 37.77106819990672)) ', 9);
Expand Down

0 comments on commit 954e710

Please sign in to comment.