mjhoptics / ray-optics

geometric ray tracing for optical systems
BSD 3-Clause "New" or "Revised" License
263 stars 54 forks source link

IndexError in appcmds.open_model if no multi-part path is provided. #145

Closed ix- closed 4 months ago

ix- commented 5 months ago

rayoptics/gui/appcmds.py l88 checks for parts and fails, as the check tries to access the second element in a tuple that only has one element. `

la4966, info = open_model("./la4966.zmx", info=True) <<< /tmp/ray-optics/./lib64/python3.11/site-packages/rayoptics/gui/appcmds.py:88, in open_model(file_url, info, post_process_imports, kwargs) <<< 86 else: <<< 87 # if we're importing another program's file, collect import info <<<---> 88 if len(file_url_pth.parts) > 0 and file_url_pth.parts[1] == 'www.photonstophotos.net': <<< 89 opm, import_info = obench.read_obench_url(file_url, kwargs) <<< <<< IndexError: tuple index out of range`

Passing a full path (multiple parts) works: `

la4966, info = open_model("/tmp/ray-optics/la4966.zmx", info=True)

`

I recommend using try: ... except: ... instead of if: ... else: ....

Cheers, -ix

mjhoptics commented 4 months ago

Hi @ix-, Thanks for the report and the suggested fix. I'd already "fixed" problems with this code several times so I went in a different but direct way to address the problem. Thanks, Mike