newville / pyshortcuts

create desktop shortcuts to python scripts on Windows, Mac, or Linux
MIT License
101 stars 15 forks source link

AttributeError crash if shortcut cmd is undefined #19

Closed maphew closed 4 years ago

maphew commented 4 years ago

If one tries to create a shortcut with an empty cmd it fails with the message AttributeError: 'NoneType' object has no attribute 'split'.

cmd = shutil.which("my-script")    # not in PATH, so returns nothing
scut = make_shortcut(cmd, name="My Script", icon=iconpath)

It could be more explicit about what's wrong. I'm not sure where's best place to put an error message, or very clear on the best practice for how.

newville commented 4 years ago

@maphew Just to be clear, are you saying we should add a test to shortcut.shortcut() that script is a string (not None or anything else) and giving a better message before doing .split()? I'm OK with that.

maphew commented 4 years ago

Yeah, something like that. It wold be helpful to emit the name of the var which has a problem (script). I swirled in confusion for awhile because I didn't know if the crash was coming from my code which surrounded the call to shortcut or inside it.