"Copy Relative Path" raises ValueError and copies nothing when the current file is not inside an open folder of the window (e.g. a single file opened on its own), or when the file and the folder are on different drives on Windows.
sublime.set_clipboard(
min(
(relpath(filename, folder) for folder in sublime.active_window().folders()),
key=len,
)
)
Reproduced with the package code (Sublime stubbed, no folders):
ValueError: min() iterable argument is empty
is_enabled() only checks that the view has a file name, so the command is offered and then fails silently (traceback in the console, no status message). With a folder on another drive, os.path.relpath raises ValueError: path is on mount 'C:', start on mount 'D:'.
Fix: skip folders that don't contain the file (catch ValueError), and fall back to the absolute path (or a status message) when the list is empty: min(candidates, key=len, default=filename).
Found while testing packages from the Package Control catalog.
"Copy Relative Path" raises
ValueErrorand copies nothing when the current file is not inside an open folder of the window (e.g. a single file opened on its own), or when the file and the folder are on different drives on Windows.Reproduced with the package code (Sublime stubbed, no folders):
is_enabled()only checks that the view has a file name, so the command is offered and then fails silently (traceback in the console, no status message). With a folder on another drive,os.path.relpathraisesValueError: path is on mount 'C:', start on mount 'D:'.Fix: skip folders that don't contain the file (catch
ValueError), and fall back to the absolute path (or a status message) when the list is empty:min(candidates, key=len, default=filename).Found while testing packages from the Package Control catalog.