Repository: microsoft/terminal (language: cpp)

Issue:
Show a more descriptive error message when the ConptyConnection fails to start for some reason
# Description of the new feature/enhancement

Show a speaking error message, when it is necessary to run Terminal with admin privileges. See https://github.com/microsoft/terminal/issues/4272 for the problem

# Proposed technical implementation details (optional)

<!-- 
A clear and concise description of what you want to happen.
-->
Show a more descriptive error message when the ConptyConnection fails to start for some reason
# Description of the new feature/enhancement

Show a speaking error message, when it is necessary to run Terminal with admin privileges. See https://github.com/microsoft/terminal/issues/4272 for the problem

# Proposed technical implementation details (optional)

<!-- 
A clear and concise description of what you want to happen.
-->


Discussion / hints:
How about just displaying the error message that matches the error code, like so:

```
[error 0x800702e4 when launching `C:\Program Files\PowerShell\6\pwsh.exe']
The requested operation requires elevation.
```

Or does Windows Terminal have to recognize the 0x800702e4 code specifically and display something more verbose?
I think displaying the error message would be perfectly fine. I had to google it. With the error message, this wouldn't have been necessary.
Could even extend that to process exit codes that look like NTSTATUS error codes:

```
[process exited with code 3221225786]
The application terminated as a result of a CTRL+C.
```

That would have a greater risk of false matches, though.
This isn't a bad idea, and I bet @DHowett thought about something like this when he first added the error codes
Yeah, we can definitely do better with these error messages!
For those who'd like to try this themselves, I added a similar kind of error message in #10045. 

Collected relevant error messages:

Symbolic Name | Error Description | Header
-- | -- | --
ERROR_ELEVATION_REQUIRED | The requested operation requires elevation. | winerror.h
STATUS_CONTROL_C_EXIT | {Application Exit by CTRL+C} The application terminated as a result of a CTRL+C. | ntstatus.h
[MSG_DIR_BAD_COMMAND_OR_FILE ](https://github.com/microsoft/terminal/issues/11073)| '%1' is not recognized as an internal or external command, operable program or batch file. | cmdmsg.h


Hello , I have read through the issue and I want to try to help in adding the new error message , Can someone guide me as to how to recreate the same runtime conditions as in #4272 ?
@Harshit-Agarwal-2022, create a Windows Terminal profile that runs `%windir%\system32\msconfig.exe`, and try to start that profile.  The application requires elevation, and this causes error 2147943140 (0x800702e4) as in <https://github.com/microsoft/terminal/issues/4272> (unless Windows Terminal itself is elevated).
@Harshit-Agarwal-2022 You still working on this issue?

@ATOMworkplace I was facing some issues with vs 2022 while building the terminal repo on my local system so i havent started with the issue yet , you can work on it if you want , I was able to recreate the error log using @KalleOlaviNiemitalo 's instructions
@Harshit-Agarwal-2022 Sure, thanks for letting me know, I'll give it a try and see what I can do.
How about just displaying the error message that matches the error code, like so:

```
[error 0x800702e4 when launching `C:\Program Files\PowerShell\6\pwsh.exe']
The requested operation requires elevation.
```

Or does Windows Terminal have to recognize the 0x800702e4 code specifically and display something more verbose?
I think displaying the error message would be perfectly fine. I had to google it. With the error message, this wouldn't have been necessary.
Could even extend that to process exit codes that look like NTSTATUS error codes:

```
[process exited with code 3221225786]
The application terminated as a result of a CTRL+C.
```

That would have a greater risk of false matches, though.
This isn't a bad idea, and I bet @DHowett thought about something like this when he first added the error codes
Yeah, we can definitely do better with these error messages!
For those who'd like to try this themselves, I added a similar kind of error message in #10045. 

Collected relevant error messages:

Symbolic Name | Error Description | Header
-- | -- | --
ERROR_ELEVATION_REQUIRED | The requested operation requires elevation. | winerror.h
STATUS_CONTROL_C_EXIT | {Application Exit by CTRL+C} The application terminated as a result of a CTRL+C. | ntstatus.h
[MSG_DIR_BAD_COMMAND_OR_FILE ](https://github.com/microsoft/terminal/issues/11073)| '%1' is not recognized as an internal or external command, operable program or batch file. | cmdmsg.h


Hello , I have read through the issue and I want to try to help in adding the new error message , Can someone guide me as to how to recreate the same runtime conditions as in #4272 ?
@Harshit-Agarwal-2022, create a Windows Terminal profile that runs `%windir%\system32\msconfig.exe`, and try to start that profile.  The application requires elevation, and this causes error 2147943140 (0x800702e4) as in <https://github.com/microsoft/terminal/issues/4272> (unless Windows Terminal itself is elevated).
@Harshit-Agarwal-2022 You still working on this issue?

@ATOMworkplace I was facing some issues with vs 2022 while building the terminal repo on my local system so i havent started with the issue yet , you can work on it if you want , I was able to recreate the error log using @KalleOlaviNiemitalo 's instructions
@Harshit-Agarwal-2022 Sure, thanks for letting me know, I'll give it a try and see what I can do.

Fix patch:
diff --git a/.github/actions/spelling/allow/allow.txt b/.github/actions/spelling/allow/allow.txt
index 630edfebce7..a936b3df359 100644
--- a/.github/actions/spelling/allow/allow.txt
+++ b/.github/actions/spelling/allow/allow.txt
@@ -11,6 +11,7 @@ colorbrewer
 commandlines
 consvc
 copyable
+CText
 dalet
 dcs
 deselection
diff --git a/src/cascadia/TerminalConnection/ConptyConnection.cpp b/src/cascadia/TerminalConnection/ConptyConnection.cpp
index 0a0b26aa934..075eb734356 100644
--- a/src/cascadia/TerminalConnection/ConptyConnection.cpp
+++ b/src/cascadia/TerminalConnection/ConptyConnection.cpp
@@ -428,6 +428,20 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation
             TerminalOutput.raise(L"\r\n");
             TerminalOutput.raise(badPathText);
         }
+        // If the requested action requires elevation, display appropriate message
+        else if (hr == HRESULT_FROM_WIN32(ERROR_ELEVATION_REQUIRED))
+        {
+            const auto elevationText = RS_(L"ElevationRequired");
+            TerminalOutput.raise(L"\r\n");
+            TerminalOutput.raise(elevationText);
+        }
+        // If the requested executable was not found, display appropriate message
+        else if (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND))
+        {
+            const auto fileNotFoundText = RS_(L"FileNotFound");
+            TerminalOutput.raise(L"\r\n");
+            TerminalOutput.raise(fileNotFoundText);
+        }
 
         _transitionToState(ConnectionState::Failed);
 
diff --git a/src/cascadia/TerminalConnection/Resources/en-US/Resources.resw b/src/cascadia/TerminalConnection/Resources/en-US/Resources.resw
index 3532e310491..82c7291a607 100644
--- a/src/cascadia/TerminalConnection/Resources/en-US/Resources.resw
+++ b/src/cascadia/TerminalConnection/Resources/en-US/Resources.resw
@@ -209,7 +209,7 @@
   </data>
   <data name="CtrlDToClose" xml:space="preserve">
     <value>You can now close this terminal with Ctrl+D, or press Enter to restart.</value>
-	  <comment>"Ctrl+D" and "Enter" represent keys the user will press (control+D and Enter).</comment>
+    <comment>"Ctrl+D" and "Enter" represent keys the user will press (control+D and Enter).</comment>
   </data>
   <data name="ProcessFailedToLaunch" xml:space="preserve">
     <value>[error {0} when launching `{1}']</value>
@@ -220,4 +220,10 @@
     <value>Could not access starting directory "{0}"</value>
     <comment>The first argument {0} is a path to a directory on the filesystem, as provided by the user.</comment>
   </data>
-</root>
+  <data name="ElevationRequired" xml:space="preserve">
+    <value>The requested operation requires elevation.</value>
+  </data>
+  <data name="FileNotFound" xml:space="preserve">
+    <value>The system cannot find the file specified.</value>
+  </data>
+</root>
\ No newline at end of file


Test patch: