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

Shell Window Error Fix #178

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

gabriel-vanca
Copy link
Contributor

Fixes #177 and improves logging for the command execute action menu feature.

@gabriel-vanca gabriel-vanca changed the base branch from main to feature/update-docs September 14, 2024 19:28
@gabriel-vanca gabriel-vanca changed the base branch from feature/update-docs to main September 14, 2024 19:33
@gabriel-vanca
Copy link
Contributor Author

Note explorer action should now be used like this:

- type          : command@1
  name          :  Open in Windows File Explorer
  command       : explorer
  arguments     : '{{ repository.path }}'

@gabriel-vanca
Copy link
Contributor Author

gabriel-vanca commented Sep 15, 2024

I tried to run:

- type          : command@1
  name          : Open in Visual Studio Code
  command       : code
  arguments     : '"{{ repository.path }}"'
  active        : file.file_exists(exe_vs_code)

Because I have VSCode installed from the Windows Store, apparently it didn't get added to the PATH environment variable.
And Windows Terminal was configured to use an old inexistent font style for CMD.exe. (I almost never use CMD.exe so I didn't notice it when I imported the profile from my old system.)

There two ways RepoM tries to run a command:

  1. First method uses the .NET native method, which is similar to using the Run:
    image
    This method would've worked if code was in the PATH variable. Because in my case it wasn't, the method failed so it tried to use the second method.
  2. Second method uses the shell. Basically it's the equivalent of typing the command in a cmd.exe window. This works and manages to start code , but because the cmd.exe profile in Windows Terminal is misconfigured, it shows a Windows Terminal error.

My fix adjust the second method by disabling the cmd.exe window. So if cmd.exe is misconfigured in Terminal, it doesn't matter because the cmd.exe window never tries to start, it just runs in the background.

The second fix that I introduced is checking the process object for NULL. This is a problem with the second method as sometimes it doesn't throw an error. For example, the following can fail to start with the first method, it tries the second method, and then fails with no error if the cmd.exe window is disabled:

- type: command@1
  name: Open in Windows File Explorer
  command: '"{{ repository.path }}"'

This is why we should always check for NULL.
Also, a fix to that is using:

- type          : command@1
  name          : Open in Windows File Explorer
  command       : explorer
  arguments     : '{{ repository.path }}'

This means the first method will always succeed and it won't have to try the second method, therefore also improving efficiency.

The rest of what I did is just improve logging. If both methods fail, then the errors from both attempts are logged as errors. If one succeeds, then they are logged as mere Information.

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

Successfully merging this pull request may close these issues.

[BUG] Shell Window Error
1 participant