diff --git a/src/cascadia/TerminalConnection/AzureConnection.cpp b/src/cascadia/TerminalConnection/AzureConnection.cpp index b8c5e31a0b9..9bddedb958b 100644 --- a/src/cascadia/TerminalConnection/AzureConnection.cpp +++ b/src/cascadia/TerminalConnection/AzureConnection.cpp @@ -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 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 diff --git a/src/cascadia/TerminalConnection/AzureConnection.h b/src/cascadia/TerminalConnection/AzureConnection.h index 4db0a9619b4..b2afd99ab2e 100644 --- a/src/cascadia/TerminalConnection/AzureConnection.h +++ b/src/cascadia/TerminalConnection/AzureConnection.h @@ -95,6 +95,8 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation std::optional _ReadUserInput(InputMode mode); web::websockets::client::websocket_client _cloudShellSocket; + + static std::optional _ParsePreferredShellType(const web::json::value& settingsResponse); }; }