[Python-ideas] Error messages for shared libraries for other platform

Andrew Barnert abarnert at yahoo.com
Mon Aug 5 18:31:15 CEST 2013


Each of the major *nix ldd/dyld families has a different set of errors, each one has half a dozen or more errors in its set, and most of them are localized. And usually the string you get back is dynamically generated by concatenating multiple different strings together. 

Let's take an example. You try to import foo.so. The module itself is fine, but it depends on libfoo.dylib. You happen to have three copies of libfoo.dylib on the path, but one is too old a version of libfoo to meet the requirement, while the next is an i386/ppc fat binary when you need x86_64, and the third is not a mach-o library at all. So, you get a four-line error message explaining that foo.so couldn't be opened because no valid libfoo image could be found, and then explaining what was wrong with each libfoo candidate. The explanations will be different between OS X 10.6 vs. 10.7-8, between English and German, etc., and completely unrelated to the messages on Linux or FreeBSD.

Besides all the parsing problems, how do you want that to appear in Python in the end result?

Sent from a random iPhone

On Aug 5, 2013, at 7:58, Ryan <rymg19 at gmail.com> wrote:

> Well, the error seems to follow this pattern:
> 
> ImportError: Cannot load library: loadsegments[number]: *number* cannot map segment from `library.so` at ...

No, that's one of a dozen or so different errors you can get on recent Linux/gnu ldd in English.

> On Windows, it always says '%1 is not a valid Win32 application'
> 
> So, could you catch the exceptions and compare the string or perform a regex match or the like?
> 
> Andrew Barnert <abarnert at yahoo.com> wrote:
>> 
>> I suspect that on most platforms, we just get a NULL return from dlopen, call dlerror, and use the error string it returns. A quick test on OS X seems to bear that out. So, short of parsing the dlerror string (or trying to parse the elf/mach-o/etc. headers ourselves), I'm not sure what we could do.
>> 
>> Sent from a random iPhone
>> 
>> On Aug 4, 2013, at 23:01, Ryan <rymg19 at gmail.com> wrote:
>> 
>>> I don't really know C. At all. I was thinking the errors could be caught at a higher level, something like(the code isn't runnable):
>>> 
>>> except windowserror as ex:
>>> if ex.string == '%1 is not...:
>>> raise_error_here
>>> 
>>> 
>>> Guido van Rossum <guido at python.org> wrote:
>>>> 
>>>> Do you know how to fix this?
>>>> 
>>>> On Sunday, August 4, 2013, Ryan wrote:
>>>>> Here are my experiences in accidently getting a .so/.dll file for the wrong chip/CPU type:
>>>>> 
>>>>> Windows:
>>>>> 
>>>>> %1 is not a valid Win32 application
>>>>> 
>>>>> *nix/Android:
>>>>> 
>>>>> A long message about improper memory mappings and such.
>>>>> 
>>>>> I'd like to propose the concept of better errors in these cases. Both Windows and Posix errors is this case are horrible, and it'd be nice for them to actually be written in English.
>>>>> -- 
>>>>> Sent from my Android phone with K-9 Mail. Please excuse my brevity.
>>> 
>>> -- 
>>> Sent from my Android phone with K-9 Mail. Please excuse my brevity.
>>> _______________________________________________
>>> Python-ideas mailing list
>>> Python-ideas at python.org
>>> http://mail.python.org/mailman/listinfo/python-ideas
> 
> -- 
> Sent from my Android phone with K-9 Mail. Please excuse my brevity.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130805/6095282a/attachment-0001.html>


More information about the Python-ideas mailing list