Commit 8e173fb2 authored by Mark Cave-Ayland's avatar Mark Cave-Ayland

Update the LWGEOM parser to provide error HINTs when being called from...

Update the LWGEOM parser to provide error HINTs when being called from PostgreSQL, and update regression tests accordingly.


git-svn-id: http://svn.osgeo.org/postgis/trunk@3113 b70326c6-7e19-0410-871a-916f4a2858ee
parent 151db5b7
......@@ -1121,6 +1121,7 @@ extern void deparse_hex(uchar str, char *result);
*/
typedef struct struct_lwgeom_parser_result
{
const char *wkinput; /* Copy of pointer to input WKT/WKB */
uchar *serialized_lwgeom; /* Pointer to serialized LWGEOM */
int size; /* Size of serialized LWGEOM in bytes */
const char *message; /* Error/warning message */
......@@ -1143,6 +1144,7 @@ typedef struct struct_lwgeom_parser_result
*/
typedef struct struct_lwgeom_unparser_result
{
uchar *serialized_lwgeom; /* Copy of pointer to input serialized LWGEOM */
char *wkoutput; /* Pointer to WKT or WKB output */
int size; /* Size of serialized LWGEOM in bytes */
const char *message; /* Error/warning message */
......
......@@ -1179,6 +1179,7 @@ parse_it(LWGEOM_PARSER_RESULT *lwg_parser_result, const char *geometry, int flag
current_parser_check_flags = flags;
lwg_parser_result->serialized_lwgeom = NULL;
lwg_parser_result->size = 0;
lwg_parser_result->wkinput = geometry;
init_parser(geometry);
......
......@@ -628,6 +628,7 @@ unparse_WKT(LWGEOM_UNPARSER_RESULT *lwg_unparser_result, uchar* serialized, allo
current_unparser_check_flags = flags;
lwg_unparser_result->wkoutput = NULL;
lwg_unparser_result->size = 0;
lwg_unparser_result->serialized_lwgeom = serialized;
unparser_ferror_occured = 0;
local_malloc=alloc;
......@@ -956,6 +957,7 @@ unparse_WKB(LWGEOM_UNPARSER_RESULT *lwg_unparser_result, uchar* serialized, allo
current_unparser_check_flags = flags;
lwg_unparser_result->wkoutput = NULL;
lwg_unparser_result->size = 0;
lwg_unparser_result->serialized_lwgeom = serialized;
unparser_ferror_occured = 0;
local_malloc=alloc;
......
......@@ -22,6 +22,7 @@ typedef struct serialized_lwgeom {
typedef struct struct_lwgeom_parser_result
{
const char *wkinput;
SERIALIZED_LWGEOM *serialized_lwgeom;
int size;
const char *message;
......@@ -30,6 +31,7 @@ typedef struct struct_lwgeom_parser_result
typedef struct struct_lwgeom_unparser_result
{
uchar *serialized_lwgeom;
char *wkoutput;
int size;
const char *message;
......
......@@ -19,10 +19,48 @@
PG_MODULE_MAGIC;
#endif
/*
* Global pointer for parser/unparser error messages
* Error message parsing functions
*
* Produces nicely formatted messages for parser/unparser errors with optional HINT
*/
char *parser_message;
void
pg_parser_errhint(LWGEOM_PARSER_RESULT *lwg_parser_result)
{
char hintbuffer[128];
char *hintstart;
char *hintfinish;
/* Generate the HINT string as the last 40 chars up until the error location */
hintbuffer[0] = '\0';
hintfinish = (char *)lwg_parser_result->wkinput + lwg_parser_result->errlocation;
if (lwg_parser_result->errlocation <= 40)
hintstart = (char *)lwg_parser_result->wkinput;
else
hintstart = hintfinish - 40;
/* If we are not at the start of the buffer, prefix with "..." */
if (hintstart != lwg_parser_result->wkinput)
strncpy(hintbuffer, "...", 3);
/* Append to the existing string */
strncat(hintbuffer, hintstart, hintfinish-hintstart);
ereport(ERROR,
(errmsg("%s", lwg_parser_result->message),
errhint("\"%s\" <-- parse error at position %d within geometry", hintbuffer, lwg_parser_result->errlocation))
);
}
void
pg_unparser_errhint(LWGEOM_UNPARSER_RESULT *lwg_unparser_result)
{
/* For the unparser simply output the error message without any associated HINT */
elog(ERROR, "%s", lwg_unparser_result->message);
}
void *
......@@ -416,5 +454,3 @@ pglwgeom_getSRID(PG_LWGEOM *lwgeom)
return lw_get_int32(loc);
}
......@@ -48,9 +48,13 @@ void pg_notice(const char *msg, va_list vp);
/*
* Standard macro for reporting parser errors to PostgreSQL
*/
extern void pg_parser_errhint(LWGEOM_PARSER_RESULT *lwg_parser_result);
extern void pg_unparser_errhint(LWGEOM_UNPARSER_RESULT *lwg_unparser_result);
#define PG_PARSER_ERROR(lwg_parser_result) \
do { \
elog(ERROR, "%s", lwg_parser_result.message); \
pg_parser_errhint(&lwg_parser_result); \
} while(0);
/*
......@@ -58,7 +62,7 @@ void pg_notice(const char *msg, va_list vp);
*/
#define PG_UNPARSER_ERROR(lwg_unparser_result) \
do { \
elog(ERROR, "%s", lwg_unparser_result.message); \
pg_unparser_errhint(&lwg_unparser_result); \
} while(0);
......
......@@ -48,20 +48,33 @@
48|MULTIPOINT(-1 -2 -3,5.4 6.6 7.77,-5.4 -6.6 -7.77,1000000 1e-6 -1000000,-1.3e-6 -1.4e-5 0)
49|GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(POINT(1 1)))
ERROR: parse error - invalid geometry
HINT: "POINT()" <-- parse error at position 7 within geometry
ERROR: parse error - invalid geometry
HINT: "POINT(1)" <-- parse error at position 8 within geometry
ERROR: parse error - invalid geometry
HINT: "POINT(," <-- parse error at position 7 within geometry
ERROR: parse error - invalid geometry
HINT: "MULTIPOINT(," <-- parse error at position 12 within geometry
ERROR: parse error - invalid geometry
HINT: "POINT(" <-- parse error at position 6 within geometry
ERROR: parse error - invalid geometry
HINT: "MULTIPOINT()" <-- parse error at position 12 within geometry
ERROR: geometry contains non-closed rings
HINT: "POLYGON( (0 0, 10 0, 10 10, 0 10)" <-- parse error at position 33 within geometry
ERROR: geometry contains non-closed rings
HINT: "... 10 10, 0 10, 0 0),(5 5, 7 5, 7 7 , 5 7)" <-- parse error at position 60 within geometry
ERROR: parse error - invalid geometry
HINT: "...TILINESTRING((0 0, 1 1),(0 0, 1 1, 2 2,)" <-- parse error at position 43 within geometry
ERROR: parse error - invalid geometry
HINT: "POINT(1 2 3," <-- parse error at position 12 within geometry
ERROR: parse error - invalid geometry
HINT: "POINT(1 2 3 4 5" <-- parse error at position 15 within geometry
ERROR: geometry requires more points
HINT: "LINESTRING(1 1)" <-- parse error at position 15 within geometry
62|POINT(inf 0)
63|POINT(-inf 0)
ERROR: parse error - invalid geometry
HINT: "MULTIPOINT(1 1, 2 2" <-- parse error at position 19 within geometry
65|t
66|f
67|t
......
......@@ -73,6 +73,7 @@ polygonize_garray|POLYGON((10 0,0 0,0 10,10 10,10 0))
linemerge149|LINESTRING(-5 -5,0 0,1 1,4 4)
intersects|f
ERROR: geometry requires more points
HINT: "POLYGON((0 0, 1 1, 0 0)" <-- parse error at position 23 within geometry
buffer|POLYGON((1 0,0.707107 -0.707107,0 -1,-0.707107 -0.707107,-1 0,-0.707107 0.707107,0 1,0.707107 0.707107,1 0))
geomunion|MULTIPOINT(0 0,1 1)
unite_garray|t
......
GEOMETRYCOLLECTION EMPTY
ERROR: parse error - invalid geometry
HINT: "POINT(EMPTY" <-- parse error at position 11 within geometry
POINT(0 0)
ERROR: parse error - invalid geometry
HINT: "POINT((" <-- parse error at position 7 within geometry
GEOMETRYCOLLECTION EMPTY
ERROR: parse error - invalid geometry
HINT: "MULTIPOINT(EMPTY" <-- parse error at position 16 within geometry
MULTIPOINT(0 0,2 0)
MULTIPOINT(0 0,2 0)
ERROR: parse error - invalid geometry
HINT: "MULTIPOINT((0 0), (2 0), EMPTY" <-- parse error at position 30 within geometry
GEOMETRYCOLLECTION EMPTY
ERROR: parse error - invalid geometry
HINT: "LINESTRING(EMPTY" <-- parse error at position 16 within geometry
LINESTRING(0 0,1 1)
ERROR: parse error - invalid geometry
HINT: "LINESTRING((" <-- parse error at position 12 within geometry
ERROR: parse error - invalid geometry
HINT: "LINESTRING((" <-- parse error at position 12 within geometry
GEOMETRYCOLLECTION EMPTY
ERROR: parse error - invalid geometry
HINT: "MULTILINESTRING(EMPTY" <-- parse error at position 21 within geometry
ERROR: parse error - invalid geometry
HINT: "MULTILINESTRING(0" <-- parse error at position 17 within geometry
MULTILINESTRING((0 0,2 0))
MULTILINESTRING((0 0,2 0),(1 1,2 2))
ERROR: parse error - invalid geometry
HINT: "...LINESTRING((0 0, 2 0), (1 1, 2 2), EMPTY" <-- parse error at position 45 within geometry
ERROR: parse error - invalid geometry
HINT: "...INESTRING((0 0, 2 0), (1 1, 2 2), (EMPTY" <-- parse error at position 46 within geometry
GEOMETRYCOLLECTION EMPTY
ERROR: parse error - invalid geometry
HINT: "POLYGON(EMPTY" <-- parse error at position 13 within geometry
POLYGON((0 0,1 0,1 1,0 1,0 0))
POLYGON((0 0,10 0,10 10,0 10,0 0),(2 2,2 5,5 5,5 2,2 2))
GEOMETRYCOLLECTION EMPTY
ERROR: parse error - invalid geometry
HINT: "MULTIPOLYGON(EMPTY" <-- parse error at position 18 within geometry
ERROR: parse error - invalid geometry
HINT: "MULTIPOLYGON((EMPTY" <-- parse error at position 19 within geometry
MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0),(2 2,2 5,5 5,5 2,2 2)))
GEOMETRYCOLLECTION EMPTY
GEOMETRYCOLLECTION EMPTY
ERROR: parse error - invalid geometry
HINT: "GEOMETRYCOLLECTION((" <-- parse error at position 20 within geometry
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment