diff --git a/src/apps/projinfo.cpp b/src/apps/projinfo.cpp index 4892d4f170..45a78c8209 100644 --- a/src/apps/projinfo.cpp +++ b/src/apps/projinfo.cpp @@ -394,8 +394,8 @@ static BaseObjectNNPtr buildObject( } } } catch (const std::exception &e) { - std::cerr << context << ": parsing of user string failed: " << e.what() - << std::endl; + std::cerr << context << ": parsing of '" << l_user_string + << "' failed: " << e.what() << std::endl; std::exit(1); } diff --git a/src/iso19111/c_api.cpp b/src/iso19111/c_api.cpp index f21216a5c0..9d378bf7d5 100644 --- a/src/iso19111/c_api.cpp +++ b/src/iso19111/c_api.cpp @@ -603,6 +603,14 @@ PJ *proj_create(PJ_CONTEXT *ctx, const char *text) { proj_context_errno_set(ctx, PROJ_ERR_INVALID_OP_WRONG_SYNTAX); } proj_log_error(ctx, __FUNCTION__, e.what()); + } catch (const NoSuchAuthorityCodeException &e) { + proj_log_error(ctx, __FUNCTION__, + std::string(e.what()) + .append(": ") + .append(e.getAuthority()) + .append(":") + .append(e.getAuthorityCode()) + .c_str()); } catch (const std::exception &e) { proj_log_error(ctx, __FUNCTION__, e.what()); } @@ -791,6 +799,14 @@ PJ *proj_create_from_database(PJ_CONTEXT *ctx, const char *auth_name, break; } return pj_obj_create(ctx, NN_NO_CHECK(obj)); + } catch (const NoSuchAuthorityCodeException &e) { + proj_log_error(ctx, __FUNCTION__, + std::string(e.what()) + .append(": ") + .append(e.getAuthority()) + .append(":") + .append(e.getAuthorityCode()) + .c_str()); } catch (const std::exception &e) { proj_log_error(ctx, __FUNCTION__, e.what()); } diff --git a/test/unit/test_c_api.cpp b/test/unit/test_c_api.cpp index b508392d93..a69f9ea6d8 100644 --- a/test/unit/test_c_api.cpp +++ b/test/unit/test_c_api.cpp @@ -232,6 +232,20 @@ TEST_F(CApi, proj_create) { ObjectKeeper keeper(obj); EXPECT_NE(obj, nullptr); } + + { + PJ_CONTEXT *ctxt = proj_context_create(); + std::string s; + proj_log_func(ctxt, &s, [](void *user_data, int, const char *msg) { + *static_cast(user_data) = msg; + }); + auto crs = proj_create(ctxt, "EPSG:i_do_not_exist"); + proj_destroy(crs); + proj_context_destroy(ctxt); + EXPECT_EQ(crs, nullptr); + EXPECT_STREQ(s.c_str(), + "proj_create: crs not found: EPSG:i_do_not_exist"); + } } // --------------------------------------------------------------------------- @@ -1094,6 +1108,22 @@ TEST_F(CApi, proj_create_from_database) { "step proj=axisswap order=2,1")); EXPECT_EQ(info.accuracy, 1); } + + { + PJ_CONTEXT *ctxt = proj_context_create(); + std::string s; + proj_log_func(ctxt, &s, [](void *user_data, int, const char *msg) { + *static_cast(user_data) = msg; + }); + auto crs = proj_create_from_database(ctxt, "EPSG", "i_do_not_exist", + PJ_CATEGORY_CRS, false, nullptr); + proj_destroy(crs); + proj_context_destroy(ctxt); + EXPECT_EQ(crs, nullptr); + EXPECT_STREQ( + s.c_str(), + "proj_create_from_database: crs not found: EPSG:i_do_not_exist"); + } } // ---------------------------------------------------------------------------