Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch errors extracting names more selectively #171

Closed
wants to merge 1 commit into from

Conversation

stevenday
Copy link
Contributor

Closes #168

@stevenday stevenday force-pushed the issues/168-encoding-errors-during-import branch from 946bebf to 1d6d01b Compare March 3, 2015 14:41
This changes the logic for extracting and decoding the name from a
feature so that Exceptions are caught more selectively and the right
errors are reported to the user.

Previously, a UnicodeDecodeError could occur when the name field
was read (because internally, the GDAL api uses force_text on
the output) and the code would catch it but instead report that the
name field didn't exist. This was confusing on files with encoding
errors.

Closes #168
@stevenday stevenday force-pushed the issues/168-encoding-errors-during-import branch from 1d6d01b to ee34937 Compare March 4, 2015 10:33
@stevenday
Copy link
Contributor Author

Hmm, the test passes fine for me locally but fails on Travis. It's failing because it's not raising an error during the import at all when I'm trying to test the error message is the right one - I wonder if it's something about my versions? (Python 2.7.3, Django 1.7)

@dracos
Copy link
Member

dracos commented Mar 4, 2015

I do get the same error locally, python 2.7.9, django 1.7.1. I think the difference will be in the version of GDAL (or underlying library) that is installed; it looks like my version is returning the string with the \x92 encoded as the illegal UTF-8 byte sequence \xc2\x92 which nonetheless decode()s in python fine.

"Could not find name using name field '%s' - should it be something else? "
"It will be one of these: %s. Specify which with --name_field" % (name_field, choices))
try:
name = feat.get(name_field)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Feature's get() throws an OGRIndexError exception if name_field isn't present, unlike the normal pythonic get(), so the None check won't be reached.

@stevenday
Copy link
Contributor Author

So since my PR has it's own problems, and it's really a problem with the underlying GDAL library, I don't think this is much of an improvement, I'll retract!

@stevenday stevenday closed this Mar 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mapit_import reports it couldn't find a name field when errors occur reading the name field
2 participants