From 370252731aec4718aa37d40d6ab285776a339d50 Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Tue, 28 May 2019 18:22:28 -0700 Subject: [PATCH] Print details of the feature when Wagyu throws an exception --- geometry.cpp | 4 ++++ tile.cpp | 30 +++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/geometry.cpp b/geometry.cpp index 7cb6cf1..b76dce2 100644 --- a/geometry.cpp +++ b/geometry.cpp @@ -268,8 +268,11 @@ drawvec clean_or_clip_poly(drawvec &geom, int z, int buffer, bool clip) { } mapbox::geometry::multi_polygon result; +#if 0 try { +#endif wagyu.execute(mapbox::geometry::wagyu::clip_type_union, result, mapbox::geometry::wagyu::fill_type_positive, mapbox::geometry::wagyu::fill_type_positive); +#if 0 } catch (std::runtime_error e) { FILE *f = fopen("/tmp/wagyu.log", "w"); fprintf(f, "%s\n", e.what()); @@ -318,6 +321,7 @@ drawvec clean_or_clip_poly(drawvec &geom, int z, int buffer, bool clip) { fprintf(stderr, "Internal error: Polygon cleaning failed. Log in /tmp/wagyu.log\n"); exit(EXIT_FAILURE); } +#endif drawvec ret; decode_clipped(result, ret); diff --git a/tile.cpp b/tile.cpp index 8f7f315..fc82a07 100644 --- a/tile.cpp +++ b/tile.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -375,6 +376,8 @@ struct partial { long long extent = 0; long long clustered = 0; std::set need_tilestats; + char *stringpool; + long long *pool_off; }; struct partial_arg { @@ -494,7 +497,30 @@ void *partial_feature_worker(void *v) { // Give Clipper a chance to try to fix it. for (size_t g = 0; g < geoms.size(); g++) { drawvec before = geoms[g]; - geoms[g] = clean_or_clip_poly(geoms[g], 0, 0, false); + try { + geoms[g] = clean_or_clip_poly(geoms[g], 0, 0, false); + } catch (const std::exception& e) { + struct partial *p = &((*partials)[i]); + + fprintf(stderr, "Failing feature:\n"); + + if (p->has_id) { + fprintf(stderr, "id %lld\n", p->id); + } + + for (size_t ii = 0; ii < p->full_keys.size(); ii++) { + fprintf(stderr, "%s: %s\n", p->full_keys[ii].c_str(), p->full_values[ii].s.c_str()); + } + for (size_t ii = 0; ii < p->keys.size(); ii++) { + fprintf(stderr, "%s: %s\n", + p->stringpool + p->pool_off[p->segment] + p->keys[ii] + 1, + p->stringpool + p->pool_off[p->segment] + p->values[ii] + 1); + } + + fflush(stderr); + throw(e); + } + if (additional[A_DEBUG_POLYGON]) { check_polygon(geoms[g]); } @@ -1992,6 +2018,8 @@ long long write_tile(FILE *geoms, std::atomic *geompos_in, char *meta p.renamed = -1; p.extent = sf.extent; p.clustered = 0; + p.stringpool = stringpool; + p.pool_off = pool_off; partials.push_back(p); }