Repository: microsoft/terminal
File: src/cascadia/TerminalConnection/ConptyConnection.cpp (C++)

Code before:

        // GH#11556 - make sure to format the error code to this string as an UNSIGNED int
        const auto failureText = RS_fmt(L"ProcessFailedToLaunch", _formatStatus(hr), _commandline);
        TerminalOutput.raise(failureText);

        // If the path was invalid, let's present an informative message to the user
        if (hr == HRESULT_FROM_WIN32(ERROR_DIRECTORY))
        {
            const auto badPathText = RS_fmt(L"BadPathText", _startingDirectory);
            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 a stop signal (ctrl+c) is detected, display appropriate message
        else if (hr == HRESULT_FROM_NT(STATUS_CONTROL_C_EXIT))
        {
            const auto ctrlCText = RS_(L"CtrlCToClose");
            TerminalOutput.raise(L"\r\n");
            TerminalOutput.raise(ctrlCText);
        }
        // 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);

        // Tear down any state we may have accumulated.
        _hPC.reset();
    }

    // Method Description:
    // - prints out the "process exited" message formatted with the exit code
    // Arguments:
    // - status: the exit code.
    void ConptyConnection::_indicateExitWithStatus(unsigned int status) noexcept
    {
        try
        {
            // GH#11556 - make sure to format the error code to this string as an UNSIGNED int
            const auto msg1 = RS_fmt(L"ProcessExited", _formatStatus(status));

Review comment (bug):
In <https://github.com/microsoft/terminal/issues/7186#issuecomment-669079974>, I suggested making Terminal recognize if a process exit code matches STATUS_CONTROL_C_EXIT.  In this pull request, you instead make Terminal instead recognize if ConptyConnection startup fails with HRESULT_FROM_NT(STATUS_CONTROL_C_EXIT).  I don't know whether ConptyConnection startup can actually fail with that error code.  How did you test this?

Code after:

        // GH#11556 - make sure to format the error code to this string as an UNSIGNED int
        const auto failureText = RS_fmt(L"ProcessFailedToLaunch", _formatStatus(hr), _commandline);
        TerminalOutput.raise(failureText);

        // If the path was invalid, let's present an informative message to the user
        if (hr == HRESULT_FROM_WIN32(ERROR_DIRECTORY))
        {
            const auto badPathText = RS_fmt(L"BadPathText", _startingDirectory);
            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);

        // Tear down any state we may have accumulated.
        _hPC.reset();
    }

    // Method Description:
    // - prints out the "process exited" message formatted with the exit code
    // Arguments:
    // - status: the exit code.
    void ConptyConnection::_indicateExitWithStatus(unsigned int status) noexcept
    {
        try
        {
            // GH#11556 - make sure to format the error code to this string as an UNSIGNED int
            const auto msg1 = RS_fmt(L"ProcessExited", _formatStatus(status));
            const auto msg2 = RS_(L"CtrlDToClose");
            const auto msg = fmt::format(FMT_COMPILE(L"\r\n{}\r\n{}\r\n"), msg1, msg2);
            TerminalOutput.raise(msg);
        }
        CATCH_LOG();
    }

    std::wstring ConptyConnection::_formatStatus(uint32_t status)