Fiona: Surface a better exception when a bad geometry type is encountered in a dataset's schema

Created on 3 May 2016  路  2Comments  路  Source: Toblerity/Fiona

An invalid geometry type in a dataset's schema raises an IndexError and doesn't provide any information instructing the user to look at their geometry type.

import fiona

profile = {
    'driver': 'ESRI Shapefile',
    'schema': {
        'geometry': 'TRASH',
        'properties': {}
    }
}

with fiona.open('test-trash-geom.shp', 'w', **profile) as dst:
    pass

results:

Traceback (most recent call last):
  File "ftrash.py", line 11, in <module>
    with fiona.open('test-trash-geom.shp', 'w', **profile) as dst:
  File "/Users/kwurster/code/Fiona/fiona/__init__.py", line 177, in open
    enabled_drivers=enabled_drivers, crs_wkt=crs_wkt)
  File "/Users/kwurster/code/Fiona/fiona/collection.py", line 162, in __init__
    self.session.start(self, **kwargs)
  File "fiona/ogrext.pyx", line 870, in fiona.ogrext.WritingSession.start (fiona/ogrext.c:15084)
    v == collection.schema.get('geometry', 'Unknown')][0],
IndexError: list index out of range
Exception ignored in: <bound method Collection.__del__ of <open Collection 'test-trash-geom.shp:test-trash-geom', mode 'w' at 0x1038a4f28>>
Traceback (most recent call last):
  File "/Users/kwurster/code/Fiona/fiona/collection.py", line 419, in __del__
  File "/Users/kwurster/code/Fiona/fiona/collection.py", line 414, in __exit__
  File "/Users/kwurster/code/Fiona/fiona/collection.py", line 398, in close
  File "/Users/kwurster/code/Fiona/fiona/collection.py", line 387, in flush
  File "fiona/ogrext.pyx", line 470, in fiona.ogrext.Session.get_length (fiona/ogrext.c:9023)
ValueError: Null layer

bug good first issue

Most helpful comment

@snorfalorpagus 馃憤 on the message, but what about a SchemaError(), which ultimately subclasses ValueError?

All 2 comments

A suggestion for a more informative message:

ValueError: Unrecognised geometry type "TRASH" in schema.

@snorfalorpagus 馃憤 on the message, but what about a SchemaError(), which ultimately subclasses ValueError?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jrheard picture jrheard  路  3Comments

epifanio picture epifanio  路  4Comments

huevosabio picture huevosabio  路  8Comments

mdklatt picture mdklatt  路  6Comments

klonuo picture klonuo  路  3Comments