Skip to content

touchy: filechooser crashes if $HOME/linuxcnc/nc_files does not exist #4005

@grandixximo

Description

@grandixximo

Summary

lib/python/touchy/filechooser.py:28-29 hardcodes the file-listing directory and crashes if the path is missing:

self.dir = os.path.join(os.getenv('HOME'), 'linuxcnc', 'nc_files')
self.reload(0)

reload() calls os.listdir(self.dir) with no try/except, raising FileNotFoundError and aborting touchy startup on any system without ~/linuxcnc/nc_files/.

Reproducer

HOME=/tmp/clean-home linuxcnc -r configs/sim/touchy/touchy.ini

Touchy aborts with:

Traceback (most recent call last):
  File ".../bin/touchy", line 887, in <module>
    hwg = touchy(sys.argv[2])
  File ".../bin/touchy", line 228, in __init__
    self.filechooser = filechooser.filechooser(...)
  File ".../lib/python/touchy/filechooser.py", line 29, in __init__
    self.reload(0)
  File ".../lib/python/touchy/filechooser.py", line 89, in reload
    self.files = os.listdir(self.dir)
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/clean-home/linuxcnc/nc_files'

How it surfaced

Caught by the new ui-smoke tests (#3999) on a clean GitHub Actions $HOME. Worked around in launch.sh by pre-creating the dir; filing this issue and a follow-up PR so the workaround can come back out.

Proposed fix

reload() should tolerate a missing or unreadable directory: catch OSError, set self.files = [], log a warning, continue. The user can still browse via the normal file menu; they just see an empty quick-pick list.

If [DISPLAY] PROGRAM_PREFIX from the INI file is available the constructor could prefer that path over the hardcoded $HOME/linuxcnc/nc_files, falling back to the existing default. PR to follow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions