rockymeza/wifi

Scheme.for_cell fails with TypeError if optional argument is not passed

Opened this issue · 2 comments

(This was reported on StackOverflow here).

An uncaught TypeError is raised when Scheme.for_cell is called for an encrypted cell, without the optional passkey argument.

When no passkey is supplied, for_cell calls configuration with passkey=None , which, if the encryption happens to be 'wpa', fails on len(passkey) in scheme.py:23:

TypeError: object of type 'NoneType' has no len()

Hi @leokoppel,

This is not a very friendly error message now is it.

I think that Scheme.for_cell could check if the cell is encrypted and then throw a TypeError about the missing passkey. Do you think that is appropriate? It would still result in an error, but at least we could control the error message.

Not sure about TypeError as the arguments given do match the function definition; they only go awry of the business logic. A custom exception like InterfaceError seems more appropriate.

I would have submitted a pull request to do this but the intended behaviour was not clear. For example, if the encryption type is 'wep', it would just return with 'wireless-key' : None and presumably fail upon trying to connect, but not before. So it's a design decision, up to you.