﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
36849	Moved GEOS Error Messages to Exceptions	David Smith	David Smith	"Capturing GEOS error messages can be a challenge as they are raised in the underlyingn C extension. In #17959 GEOS error messages were moved to logs, see 53c8b2c0c52cf999b644184bfe51e9f59d89286e. 

Here is an example of the current output. Firstly an error is logged and later you have an Exception.

{{{
>>> from django.contrib.gis.geos import GEOSGeometry
>>> GEOSGeometry(""POINT (5, 23)"")
GEOS_ERROR: ParseException: Expected number but encountered ','

Traceback (most recent call last):
  File ""<python-input-1>"", line 1, in <module>
    GEOSGeometry(""POINT (5, 23)"")
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File ""C:\Users\smith\projects\django\django\contrib\gis\geos\geometry.py"", line 766, in __init__
    g = self._from_wkt(force_bytes(wkt_m[""wkt""]))
  File ""C:\Users\smith\projects\django\django\contrib\gis\geos\geometry.py"", line 139, in _from_wkt
    return wkt_r().read(wkt)
           ~~~~~~~~~~~~^^^^^
  File ""C:\Users\smith\projects\django\django\contrib\gis\geos\prototypes\io.py"", line 160, in read
    return wkt_reader_read(self.ptr, force_bytes(wkt))
  File ""C:\Users\smith\projects\django\django\contrib\gis\geos\libgeos.py"", line 154, in __call__
    return self.func(*args)
           ~~~~~~~~~^^^^^^^
  File ""C:\Users\smith\projects\django\django\contrib\gis\geos\prototypes\threadsafe.py"", line 47, in __call__
    return self.cfunc(self.thread_context.handle.ptr, *args)
           ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ""C:\Users\smith\projects\django\django\contrib\gis\geos\prototypes\errcheck.py"", line 35, in check_geom
    raise GEOSException(
    ...<2 lines>...
    )
django.contrib.gis.geos.error.GEOSException: Error encountered checking Geometry returned from GEOS C function ""GEOSWKTReader_read_r"".
}}}

I propose to move the GEOS error message to the exception message.

{{{
>>> from django.contrib.gis.geos import GEOSGeometry
>>> GEOSGeometry(""POINT (5, 23)"")
Traceback (most recent call last):
  File ""<python-input-1>"", line 1, in <module>
    GEOSGeometry(""POINT (5, 23)"")
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File ""C:\Users\smith\projects\django\django\contrib\gis\geos\geometry.py"", line 766, in __init__
    g = self._from_wkt(force_bytes(wkt_m[""wkt""]))
  File ""C:\Users\smith\projects\django\django\contrib\gis\geos\geometry.py"", line 139, in _from_wkt
    return wkt_r().read(wkt)
           ~~~~~~~~~~~~^^^^^
  File ""C:\Users\smith\projects\django\django\contrib\gis\geos\prototypes\io.py"", line 160, in read
    return wkt_reader_read(self.ptr, force_bytes(wkt))
  File ""C:\Users\smith\projects\django\django\contrib\gis\geos\libgeos.py"", line 155, in __call__
    return self.func(*args)
           ~~~~~~~~~^^^^^^^
  File ""C:\Users\smith\projects\django\django\contrib\gis\geos\prototypes\threadsafe.py"", line 48, in __call__
    return self.cfunc(self.thread_context.handle.ptr, *args)
           ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ""C:\Users\smith\projects\django\django\contrib\gis\geos\prototypes\errcheck.py"", line 47, in check_geom
    raise GEOSException(error_msg)
django.contrib.gis.geos.error.GEOSException: Error encountered checking Geometry returned from GEOS C function ""GEOSWKTReader_read_r"". ParseException: Expected number but encountered ','
>>> 
}}}

This would make the error appear inline with the exception rather than as a separate message. I also found that the Django test suite doesn't have any logging output configured by default so these messages can be difficult to spot. 

I'll attach a tentative patch to show how this could be achieved. 
"	Cleanup/optimization	assigned	GIS	6.0	Normal			Claude Paroz	Accepted	1	0	0	0	0	0
