aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/filemanager.cpp37
-rw-r--r--src/iso19111/c_api.cpp5
-rw-r--r--test/gie/4D-API_cs2cs-style.gie6
3 files changed, 25 insertions, 23 deletions
diff --git a/src/filemanager.cpp b/src/filemanager.cpp
index 8ab8e6c4..02845a8f 100644
--- a/src/filemanager.cpp
+++ b/src/filemanager.cpp
@@ -1420,6 +1420,21 @@ static void *pj_open_lib_internal(
if (out_full_filename != nullptr && out_full_filename_size > 0)
out_full_filename[0] = '\0';
+ auto open_lib_from_paths = [&ctx, open_file, &name, &fname, &sysname, &mode](const std::string & projLibPaths) {
+ void *lib_fid = nullptr;
+ auto paths = NS_PROJ::internal::split(projLibPaths, dirSeparator);
+ for (const auto& path : paths) {
+ fname = NS_PROJ::internal::stripQuotes(path);
+ fname += DIR_CHAR;
+ fname += name;
+ sysname = fname.c_str();
+ lib_fid = open_file(ctx, sysname, mode);
+ if (lib_fid)
+ break;
+ }
+ return lib_fid;
+ };
+
/* check if ~/name */
if (is_tilde_slash(name))
if ((sysname = getenv("HOME")) != nullptr) {
@@ -1487,16 +1502,7 @@ static void *pj_open_lib_internal(
else if (!gbPROJ_LIB_ENV_VAR_TRIED_LAST &&
!(projLib = NS_PROJ::FileManager::getProjLibEnvVar(ctx))
.empty()) {
- auto paths = NS_PROJ::internal::split(projLib, dirSeparator);
- for (const auto &path : paths) {
- fname = path;
- fname += DIR_CHAR;
- fname += name;
- sysname = fname.c_str();
- fid = open_file(ctx, sysname, mode);
- if (fid)
- break;
- }
+ fid = open_lib_from_paths(projLib);
}
else if ((sysname = get_path_from_relative_share_proj(
@@ -1519,16 +1525,7 @@ static void *pj_open_lib_internal(
else if (gbPROJ_LIB_ENV_VAR_TRIED_LAST &&
!(projLib = NS_PROJ::FileManager::getProjLibEnvVar(ctx))
.empty()) {
- auto paths = NS_PROJ::internal::split(projLib, dirSeparator);
- for (const auto &path : paths) {
- fname = path;
- fname += DIR_CHAR;
- fname += name;
- sysname = fname.c_str();
- fid = open_file(ctx, sysname, mode);
- if (fid)
- break;
- }
+ fid = open_lib_from_paths(projLib);
}
else {
diff --git a/src/iso19111/c_api.cpp b/src/iso19111/c_api.cpp
index 527ccd4f..4823213b 100644
--- a/src/iso19111/c_api.cpp
+++ b/src/iso19111/c_api.cpp
@@ -572,6 +572,11 @@ PJ *proj_create(PJ_CONTEXT *ctx, const char *text) {
if (identifiedObject) {
return pj_obj_create(ctx, NN_NO_CHECK(identifiedObject));
}
+ } catch (const io::ParsingException &e) {
+ if (proj_context_errno(ctx) == 0) {
+ proj_context_errno_set(ctx, PROJ_ERR_INVALID_OP_WRONG_SYNTAX);
+ }
+ proj_log_error(ctx, __FUNCTION__, e.what());
} catch (const std::exception &e) {
proj_log_error(ctx, __FUNCTION__, e.what());
}
diff --git a/test/gie/4D-API_cs2cs-style.gie b/test/gie/4D-API_cs2cs-style.gie
index 9189b328..1b0c1541 100644
--- a/test/gie/4D-API_cs2cs-style.gie
+++ b/test/gie/4D-API_cs2cs-style.gie
@@ -533,11 +533,11 @@ expect 0 0 1
roundtrip 1
-------------------------------------------------------------------------------
-# Check that proj_create() returns a generic error when an exception is caught
+# Check that proj_create() returns a syntax error when an exception is caught
# in the creation of a PJ object.
-------------------------------------------------------------------------------
-operation this is a bogus CRS meant to trigger a generic error in proj_create()
-expect failure errno other
+operation this is a bogus CRS meant to trigger a syntax error in proj_create()
+expect failure errno invalid_op_wrong_syntax
-------------------------------------------------------------------------------
# Test proj=set