#36849: Moved GEOS Error Messages to Exceptions
-----------------------------+-----------------------------------------
     Reporter:  David Smith  |                     Type:  Uncategorized
       Status:  new          |                Component:  GIS
      Version:  6.0          |                 Severity:  Normal
     Keywords:               |             Triage Stage:  Unreviewed
    Has patch:  0            |      Needs documentation:  0
  Needs tests:  0            |  Patch needs improvement:  0
Easy pickings:  0            |                    UI/UX:  0
-----------------------------+-----------------------------------------
 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.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36849>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019b98c7accf-1ef501c4-8df6-469a-a651-6b88bdbbd231-000000%40eu-central-1.amazonses.com.

Reply via email to