Azure: fall back to powershell when no preferred shell is set (#8197)
I am still not sure what is the full set of scenarios that the problem might occur, but for me it occurred for an "old" cloud shell account, and didn't reproduce since I have reconfigured it. These behavior might be explained by the fact that "preferred shell type" did not exist in the API originally and thus was not set. In such case, Terminal succeeds to retrieve to the settings but then crashes when reading the missing field. To fix it, I handle the case where the field is missing and fallback to PowerShell. ## Validation Steps Performed * Tested manually, only once. Closes #7056
This commit is contained in:
parent
e9a7b24296
commit
0c0830b2f2
|
@ -687,6 +687,25 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation
|
|||
_state = AzureState::TermConnecting;
|
||||
}
|
||||
|
||||
// Method description:
|
||||
// - Helper function to parse the preferred shell type from user settings returned by cloud console API.
|
||||
// We need this function because the field might be missing in the settings
|
||||
// created with old versions of cloud console API.
|
||||
std::optional<utility::string_t> AzureConnection::_ParsePreferredShellType(const web::json::value& settingsResponse)
|
||||
{
|
||||
if (settingsResponse.has_object_field(L"properties"))
|
||||
{
|
||||
const auto userSettings = settingsResponse.at(L"properties");
|
||||
if (userSettings.has_string_field(L"preferredShellType"))
|
||||
{
|
||||
const auto preferredShellTypeValue = userSettings.at(L"preferredShellType");
|
||||
return preferredShellTypeValue.as_string();
|
||||
}
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
// Method description:
|
||||
// - helper function to connect the user to the Azure cloud shell
|
||||
void AzureConnection::_RunConnectState()
|
||||
|
@ -706,9 +725,9 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation
|
|||
_WriteStringWithNewline(RS_(L"AzureSuccess"));
|
||||
|
||||
// Request for a terminal for said cloud shell
|
||||
const auto shellType = settingsResponse.at(L"properties").at(L"preferredShellType").as_string();
|
||||
const auto shellType = _ParsePreferredShellType(settingsResponse);
|
||||
_WriteStringWithNewline(RS_(L"AzureRequestingTerminal"));
|
||||
const auto socketUri = _GetTerminal(shellType);
|
||||
const auto socketUri = _GetTerminal(shellType.value_or(L"pwsh"));
|
||||
_TerminalOutputHandlers(L"\r\n");
|
||||
|
||||
// Step 8: connecting to said terminal
|
||||
|
|
|
@ -95,6 +95,8 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation
|
|||
std::optional<std::wstring> _ReadUserInput(InputMode mode);
|
||||
|
||||
web::websockets::client::websocket_client _cloudShellSocket;
|
||||
|
||||
static std::optional<utility::string_t> _ParsePreferredShellType(const web::json::value& settingsResponse);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue