Skip to content

Commit

Permalink
Merge pull request #4113 from rouault/fix_4112
Browse files Browse the repository at this point in the history
proj_create()/proj_create_from_database(): recall CRS AUTH:CODE in error message
  • Loading branch information
rouault committed Apr 6, 2024
2 parents f4af277 + 4bc2bc6 commit 356e255
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/apps/projinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
16 changes: 16 additions & 0 deletions src/iso19111/c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down Expand Up @@ -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());
}
Expand Down
30 changes: 30 additions & 0 deletions test/unit/test_c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string *>(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");
}
}

// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -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<std::string *>(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");
}
}

// ---------------------------------------------------------------------------
Expand Down

0 comments on commit 356e255

Please sign in to comment.