aboutsummaryrefslogtreecommitdiff
path: root/src/strerrno.cpp
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2020-12-15 00:51:46 +0100
committerEven Rouault <even.rouault@spatialys.com>2020-12-15 01:13:43 +0100
commit244a24104ded3a4573aeffa32160af21f76cbce6 (patch)
treef3a11529172719657cf7576e062e45e0f9452db5 /src/strerrno.cpp
parent1e9894b0e2b161e61546672bccb85a9ef21df541 (diff)
downloadPROJ-244a24104ded3a4573aeffa32160af21f76cbce6.tar.gz
PROJ-244a24104ded3a4573aeffa32160af21f76cbce6.zip
Revise error codes to have a reduced set exposed in the public API.
Fixes #2482 And also add proj_context_errno_string() Revise gie 'expect failure errno XXXX' strings
Diffstat (limited to 'src/strerrno.cpp')
-rw-r--r--src/strerrno.cpp143
1 files changed, 54 insertions, 89 deletions
diff --git a/src/strerrno.cpp b/src/strerrno.cpp
index 3d0131c6..f94de55d 100644
--- a/src/strerrno.cpp
+++ b/src/strerrno.cpp
@@ -8,103 +8,68 @@
#include "proj_config.h"
#include "proj_internal.h"
-static const char * const
-pj_err_list[] = {
- "no arguments in initialization list", /* -1 */
- "no options found in 'init' file", /* -2 */
- "no colon in init= string", /* -3 */
- "projection not named", /* -4 */
- "unknown projection id", /* -5 */
- "effective eccentricity < 0 or >= 1.", /* -6 */
- "unknown unit conversion id", /* -7 */
- "invalid boolean param argument", /* -8 */
- "unknown elliptical parameter name", /* -9 */
- "reciprocal flattening (1/f) = 0", /* -10 */
- "|radius reference latitude| > 90", /* -11 */
- "squared eccentricity < 0", /* -12 */
- "major axis or radius = 0 or not given", /* -13 */
- "latitude or longitude exceeded limits", /* -14 */
- "invalid x or y", /* -15 */
- "improperly formed DMS value", /* -16 */
- "non-convergent inverse meridional dist", /* -17 */
- "non-convergent sinh(psi) to tan(phi)", /* -18 */
- "acos/asin: |arg| >1.+1e-14", /* -19 */
- "tolerance condition error", /* -20 */
- "conic lat_1 = -lat_2", /* -21 */
- "lat_0, lat_1 or lat_2 >= 90", /* -22 */
- "lat_1 = 0", /* -23 */
- "lat_ts >= 90", /* -24 */
- "no distance between control points", /* -25 */
- "projection not selected to be rotated", /* -26 */
- "W <= 0 or M <= 0", /* -27 */
- "lsat not in 1-5 range", /* -28 */
- "path not in range", /* -29 */
- "h <= 0 or h > 1e10 * a", /* -30 */
- "k <= 0", /* -31 */
- "lat_1=lat_2 or lat_1=0 or lat_2=90", /* -32 */
- "lat_0 = 0 or 90 or alpha = 90", /* -33 */
- "elliptical usage required", /* -34 */
- "invalid UTM zone number", /* -35 */
- "", /* no longer used */ /* -36 */
- "failed to find projection to be rotated", /* -37 */
- "failed to load datum shift file", /* -38 */
- "both n & m must be spec'd and > 0", /* -39 */
- "n <= 0, n > 1 or not specified", /* -40 */
- "lat_1 or lat_2 not specified", /* -41 */
- "|lat_1| == |lat_2|", /* -42 */
- "lat_0 is pi/2 from mean lat", /* -43 */
- "unparseable coordinate system definition", /* -44 */
- "geocentric transformation missing z or ellps", /* -45 */
- "unknown prime meridian conversion id", /* -46 */
- "illegal axis orientation combination", /* -47 */
- "point not within available datum shift grids", /* -48 */
- "invalid sweep axis, choose x or y", /* -49 */
- "malformed pipeline", /* -50 */
- "unit conversion factor must be > 0", /* -51 */
- "invalid scale", /* -52 */
- "non-convergent computation", /* -53 */
- "missing required arguments", /* -54 */
- "lat_0 = 0", /* -55 */
- "ellipsoidal usage unsupported", /* -56 */
- "only one +init allowed for non-pipeline operations", /* -57 */
- "argument not numerical or out of range", /* -58 */
- "inconsistent unit type between input and output", /* -59 */
- "arguments are mutually exclusive", /* -60 */
- "generic error of unknown origin", /* -61 */
- "network error", /* -62 */
- /* When adding error messages, remember to update ID defines in
- src/proj_internal.h and src/apps/gie.cpp */
-};
+const char* proj_errno_string(int err) {
+ return proj_context_errno_string(pj_get_default_ctx(), err);
+}
+static const struct
+{
+ int num;
+ const char *str;
+} error_strings[] = {
-const char* proj_errno_string(int err) {
- const int max_error = 9999;
- static char note[50];
- size_t adjusted_err;
+ { PROJ_ERR_INVALID_OP_WRONG_SYNTAX, _("Invalid PROJ string syntax") },
+ { PROJ_ERR_INVALID_OP_MISSING_ARG, _("Missing argument") },
+ { PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE, _("Invalid value for an argument") },
+ { PROJ_ERR_INVALID_OP_MUTUALLY_EXCLUSIVE_ARGS, _("Mutually exclusive arguments") },
+ { PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID, _("File not found or invalid") },
+ { PROJ_ERR_COORD_TRANSFM_INVALID_COORD, _("Invalid coordinate") },
+ { PROJ_ERR_COORD_TRANSFM_OUTSIDE_PROJECTION_DOMAIN, _("Point outside of projection domain") },
+ { PROJ_ERR_COORD_TRANSFM_NO_OPERATION, _("No operation matching criteria found for coordinate") },
+ { PROJ_ERR_COORD_TRANSFM_OUTSIDE_GRID, _("Coordinate to transform falls outside grid") },
+ { PROJ_ERR_COORD_TRANSFM_GRID_AT_NODATA, _("Coordinate to transform falls into a grid cell that evaluates to nodata") },
+ { PROJ_ERR_OTHER_API_MISUSE, _("API misuse") },
+ { PROJ_ERR_OTHER_NO_INVERSE_OP, _("No inverse operation") },
+ { PROJ_ERR_OTHER_NETWORK_ERROR, _("Network error when accessing a remote resource") },
+};
+
+const char PROJ_DLL * proj_context_errno_string(PJ_CONTEXT* ctx, int err)
+{
+ if( ctx == nullptr )
+ ctx = pj_get_default_ctx();
if (0==err)
return nullptr;
- /* System error codes are positive */
- if (err > 0) {
-#ifdef HAVE_STRERROR
- return strerror(err);
-#else
- /* Defend string boundary against exorbitantly large err values */
- /* which may occur on platforms with 64-bit ints */
- sprintf(note, "no system list, errno: %d\n",
- (err < max_error) ? err: max_error);
- return note;
-#endif
+ const char* str = nullptr;
+ for( const auto& num_str_pair: error_strings )
+ {
+ if( err == num_str_pair.num )
+ {
+ str = num_str_pair.str;
+ break;
+ }
}
- /* PROJ error codes are negative: -1 to -9999 */
- adjusted_err = err < -max_error ? max_error : -err - 1;
- if (adjusted_err < (sizeof(pj_err_list) / sizeof(char *)))
- return (char *)pj_err_list[adjusted_err];
+ if( str == nullptr && err > 0 && (err & PROJ_ERR_INVALID_OP) != 0 )
+ {
+ str = _("Unspecified error related to coordinate operation initialization");
+ }
+ if( str == nullptr && err > 0 && (err & PROJ_ERR_COORD_TRANSFM) != 0 )
+ {
+ str = _("Unspecified error related to coordinate transformation");
+ }
- sprintf(note, "invalid projection system error (%d)",
- (err > -max_error) ? err: -max_error);
- return note;
+ if (str) {
+ ctx->lastFullErrorMessage = str;
+ }
+ else
+ {
+ ctx->lastFullErrorMessage.resize(50);
+ snprintf(&ctx->lastFullErrorMessage[0], ctx->lastFullErrorMessage.size(),
+ _("Unknown error (code %d)"), err);
+ ctx->lastFullErrorMessage.resize(strlen(ctx->lastFullErrorMessage.data()));
+ }
+ return ctx->lastFullErrorMessage.c_str();
}