/src/proj/src/strerrno.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* list of projection system errno values */ |
2 | | |
3 | | #include <stddef.h> |
4 | | #include <stdio.h> |
5 | | #include <string.h> |
6 | | |
7 | | #include "proj.h" |
8 | | #include "proj_config.h" |
9 | | #include "proj_internal.h" |
10 | | |
11 | 2.81k | const char *proj_errno_string(int err) { |
12 | 2.81k | return proj_context_errno_string(pj_get_default_ctx(), err); |
13 | 2.81k | } |
14 | | |
15 | | static const struct { |
16 | | int num; |
17 | | const char *str; |
18 | | } error_strings[] = { |
19 | | |
20 | | {PROJ_ERR_INVALID_OP_WRONG_SYNTAX, _("Invalid PROJ string syntax")}, |
21 | | {PROJ_ERR_INVALID_OP_MISSING_ARG, _("Missing argument")}, |
22 | | {PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE, _("Invalid value for an argument")}, |
23 | | {PROJ_ERR_INVALID_OP_MUTUALLY_EXCLUSIVE_ARGS, |
24 | | _("Mutually exclusive arguments")}, |
25 | | {PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID, |
26 | | _("File not found or invalid")}, |
27 | | {PROJ_ERR_COORD_TRANSFM_INVALID_COORD, _("Invalid coordinate")}, |
28 | | {PROJ_ERR_COORD_TRANSFM_OUTSIDE_PROJECTION_DOMAIN, |
29 | | _("Point outside of projection domain")}, |
30 | | {PROJ_ERR_COORD_TRANSFM_NO_OPERATION, |
31 | | _("No operation matching criteria found for coordinate")}, |
32 | | {PROJ_ERR_COORD_TRANSFM_OUTSIDE_GRID, |
33 | | _("Coordinate to transform falls outside grid")}, |
34 | | {PROJ_ERR_COORD_TRANSFM_GRID_AT_NODATA, |
35 | | _("Coordinate to transform falls into a grid cell that evaluates to " |
36 | | "nodata")}, |
37 | | {PROJ_ERR_COORD_TRANSFM_NO_CONVERGENCE, |
38 | | _("Iterative method fails to converge on coordinate to transform")}, |
39 | | {PROJ_ERR_COORD_TRANSFM_MISSING_TIME, |
40 | | _("Coordinate to transform lacks time")}, |
41 | | {PROJ_ERR_OTHER_API_MISUSE, _("API misuse")}, |
42 | | {PROJ_ERR_OTHER_NO_INVERSE_OP, _("No inverse operation")}, |
43 | | {PROJ_ERR_OTHER_NETWORK_ERROR, |
44 | | _("Network error when accessing a remote resource")}, |
45 | | }; |
46 | | |
47 | 10.4k | const char *proj_context_errno_string(PJ_CONTEXT *ctx, int err) { |
48 | 10.4k | if (ctx == nullptr) |
49 | 0 | ctx = pj_get_default_ctx(); |
50 | | |
51 | 10.4k | if (0 == err) |
52 | 0 | return nullptr; |
53 | | |
54 | 10.4k | const char *str = nullptr; |
55 | 30.0k | for (const auto &num_str_pair : error_strings) { |
56 | 30.0k | if (err == num_str_pair.num) { |
57 | 9.82k | str = num_str_pair.str; |
58 | 9.82k | break; |
59 | 9.82k | } |
60 | 30.0k | } |
61 | | |
62 | 10.4k | if (str == nullptr && err > 0 && (err & PROJ_ERR_INVALID_OP) != 0) { |
63 | 0 | str = _( |
64 | 0 | "Unspecified error related to coordinate operation initialization"); |
65 | 0 | } |
66 | 10.4k | if (str == nullptr && err > 0 && (err & PROJ_ERR_COORD_TRANSFM) != 0) { |
67 | 0 | str = _("Unspecified error related to coordinate transformation"); |
68 | 0 | } |
69 | | |
70 | 10.4k | if (str) { |
71 | 9.82k | ctx->lastFullErrorMessage = str; |
72 | 9.82k | } else { |
73 | 667 | ctx->lastFullErrorMessage.resize(50); |
74 | 667 | snprintf(&ctx->lastFullErrorMessage[0], |
75 | 667 | ctx->lastFullErrorMessage.size(), _("Unknown error (code %d)"), |
76 | 667 | err); |
77 | 667 | ctx->lastFullErrorMessage.resize( |
78 | 667 | strlen(ctx->lastFullErrorMessage.data())); |
79 | 667 | } |
80 | 10.4k | return ctx->lastFullErrorMessage.c_str(); |
81 | 10.4k | } |