Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle Invalid GIT_EDITOR #3

Open
wookie184 opened this issue Jun 26, 2022 · 1 comment
Open

Handle Invalid GIT_EDITOR #3

wookie184 opened this issue Jun 26, 2022 · 1 comment
Labels
question Further information is requested

Comments

@wookie184
Copy link

wookie184 commented Jun 26, 2022

Noticed because of this: microsoft/vscode#153246

This error is raised when running blurb with an invalid GIT_EDITOR environment variable ("c:\Users\wookie184\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\git\dist\git-editor.sh" on windows in my case).

PS C:\Users\wookie184\Documents\GitHub\cpython> blurb
Traceback (most recent call last):
  File "c:\users\wookie184\appdata\local\programs\python\python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\wookie184\appdata\local\programs\python\python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\wookie184\AppData\Local\Programs\Python\Python39\Scripts\blurb.exe\__main__.py", line 7, in <module>
  File "c:\users\wookie184\appdata\local\programs\python\python39\lib\site-packages\blurb.py", line 1659, in main
    sys.exit(fn(*filtered_args, **kwargs))
  File "c:\users\wookie184\appdata\local\programs\python\python39\lib\site-packages\blurb.py", line 935, in add
    subprocess.run(args)
  File "c:\users\wookie184\appdata\local\programs\python\python39\lib\subprocess.py", line 505, in run
    with Popen(*popenargs, **kwargs) as process:
  File "c:\users\wookie184\appdata\local\programs\python\python39\lib\subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "c:\users\wookie184\appdata\local\programs\python\python39\lib\subprocess.py", line 1420, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
OSError: [WinError 193] %1 is not a valid Win32 application

It isn't very clear to the user what the issue is from this error. Possible solutions:

  • Handle the error and reraise a specific error mentioning what failed to run (e.g. that GIT_EDITOR was invalid if that is the case).
  • Handle the error and try to use a fallback (e.g. notepad on windows) if GIT_EDITOR fails.

If we decide to do one of these I'd be happy to try implementing it.

Thanks!

@ezio-melotti ezio-melotti added the question Further information is requested label Jun 26, 2022
@hugovk hugovk transferred this issue from python/core-workflow Mar 27, 2024
@hugovk
Copy link
Member

hugovk commented Jan 6, 2025

Thanks for the report and sorry for the long delay in answering!

Do you know if VS Code still sets a .sh file as GIT_EDITOR? It looks they've fixed it? microsoft/vscode#153246 (comment)


We do have some fallbacks, first in find_editor which will fall back to notepad.exe on Windows if there's no editor env var set:

blurb/src/blurb/blurb.py

Lines 802 to 818 in 65941da

def find_editor():
for var in 'GIT_EDITOR', 'EDITOR':
editor = os.environ.get(var)
if editor is not None:
return editor
if sys.platform == 'win32':
fallbacks = ['notepad.exe']
else:
fallbacks = ['/etc/alternatives/editor', 'nano']
for fallback in fallbacks:
if os.path.isabs(fallback):
found_path = fallback
else:
found_path = shutil.which(fallback)
if found_path and os.path.exists(found_path):
return found_path
error('Could not find an editor! Set the EDITOR environment variable.')

But in this case, it is set.

And then later, also check the editor file exists:

blurb/src/blurb/blurb.py

Lines 857 to 862 in 65941da

if shutil.which(editor):
args = [editor]
else:
args = list(shlex.split(editor))
if not shutil.which(args[0]):
sys.exit(f"Invalid GIT_EDITOR / EDITOR value: {editor}")

But in this case, it does exist.

So I think we could do one of your suggested options, if we think it's likely to occur again (although we've not had any other reports for this or reactions to this issue).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants