skunkwerks / snappy-erlang-nif

An Erlang NIF wrapper for Google's snappy compressor/decompressor
89 stars 64 forks source link

Supressing nif load errors #19

Open frekw opened 7 years ago

frekw commented 7 years ago

Hi!

Just having spent some time trying to understand why snappy-erlang-nif failed to load on my production system, could I suggest either removing the catch here: https://github.com/fdmanana/snappy-erlang-nif/blob/master/src/snappy.erl#L36 or making it optional? :)

Unfortunately, my Erlang chops are a pretty much non-existant, otherwise I'd send a pull request.

Best, Fredrik

dch commented 7 years ago

The catch is supposed to be there - if your NIF isn't compiled correctly, or not available, and you are including/using the library module in your code, you want this to fail. Or have I missed something?

frekw commented 7 years ago

Yes, but the catch silences the failure to load the NIF. So during application start it appears as if everything has loaded properly but all calls fail with snappy_nif_not_loaded and you don't get any indication as to why.

dch commented 7 years ago

@frekw the try/catch is in place because this code was originally written when not all versions of erlang could support NIFs, and the parent library then would need to handle it. I think now we can safely remove this check completely.