Print file fails if there are no valid gcode files

Basic Information:

Klipper master from git

Describe your issue:

virtual_sdcard file open
Traceback (most recent call last):
  File "klipper/klippy/extras/virtual_sdcard.py", line 184, in _load_file
    fname = files_by_lower[fname.lower()]
            ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
KeyError: 'test.nc'
Unable to open file

To reproduce start with an empty gcode directory. Then upload a file with any extension that isn’t a “valid” gcode file. For example a file xxxx.nc which is a common extension that Klipper doesn’t recognize. Then select print file and it will get an “unable to open file” error which is misleading.

I only looked briefly at the code and I don’t really understand what the purpose of that code is. It’s creating a list of files then checking if the file selected to print is in that list so you end up in a situation where the file exists but it’s not in the list. If there are no valid files then it will get a confusing error because the list is empty.

The error message should reflect that the selected file has an invalid extension or something similar. Also, I request that “nc” be added as a valid extension. :grinning:

Still looking for an acknowledgement. Is over 1 month enough time?

Nice forum here. Complain when I do then when I don’t, prove that my original complaint was valid.

I’m not sure what you are expecting.
It is true that Klipper only supports ['gcode', 'g', 'gco'] as valid extensions, and that it reacts with Unable to open file when using another extension.
It is also true that this error message could be more clear.

I’m not aware of a single slicer that would natively create .nc and e.g. Cura does not even know it. So I would not call it a common extension in 3D printing and Klipper is a 3D printing firmware.

Overall, yes this could be improved, but seems rather an edge case with a low impact. As such an interested developer could pick it up if his time permits.

2 Likes