@@ -393,31 +393,45 @@ void AppCommandlineArgs::_buildFocusTabParser()
393393 if (!_focusTabSession.empty ())
394394 {
395395 // Focus tab by session GUID
396- focusTabAction.Action (ShortcutAction::SwitchToTab);
397- SwitchToTabArgs args{};
398396 const auto str = winrt::to_hstring (_focusTabSession);
399397 // GuidFromPlainString handles GUIDs without braces (e.g. "12345678-...")
400398 // GuidFromString handles GUIDs with braces (e.g. "{12345678-...}")
401399 // Try plain first (most common from WT_SESSION), fall back to braced
402400 winrt::guid id{};
401+ bool parsedSuccessfully = false ;
403402 try
404403 {
405- id = ::Microsoft::Console::Utils::GuidFromPlainString (str.c_str ());
404+ try
405+ {
406+ id = ::Microsoft::Console::Utils::GuidFromPlainString (str.c_str ());
407+ }
408+ catch (...)
409+ {
410+ id = ::Microsoft::Console::Utils::GuidFromString (str.c_str ());
411+ }
412+ parsedSuccessfully = true ;
406413 }
407414 catch (...)
408415 {
409- id = ::Microsoft::Console::Utils::GuidFromString (str.c_str ());
416+ // Invalid GUID provided - silently ignore similar to how invalid
417+ // tab colors are handled. The command will be skipped.
410418 }
411- args.SessionId (id);
412- focusTabAction.Args (args);
413- _startupActions.push_back (focusTabAction);
414-
415- // When targeting by session ID, route to an existing window on the
416- // current desktop (if user didn't specify -w explicitly).
417- // The session ID uniquely identifies a pane in some window.
418- if (_windowTarget.empty ())
419+
420+ if (parsedSuccessfully)
419421 {
420- _windowTarget = " 0" ;
422+ focusTabAction.Action (ShortcutAction::SwitchToTab);
423+ SwitchToTabArgs args{};
424+ args.SessionId (id);
425+ focusTabAction.Args (args);
426+ _startupActions.push_back (focusTabAction);
427+
428+ // When targeting by session ID, route to an existing window on the
429+ // current desktop (if user didn't specify -w explicitly).
430+ // The session ID uniquely identifies a pane in some window.
431+ if (_windowTarget.empty ())
432+ {
433+ _windowTarget = " 0" ;
434+ }
421435 }
422436 }
423437 else if (_focusTabIndex >= 0 )
@@ -736,8 +750,16 @@ NewTerminalArgs AppCommandlineArgs::_getNewTerminalArgs(AppCommandlineArgs::NewT
736750 if (*subcommand.sessionIdOption )
737751 {
738752 const auto str = winrt::to_hstring (_sessionId);
739- const auto id = ::Microsoft::Console::Utils::GuidFromString (str.c_str ());
740- args.SessionId (id);
753+ try
754+ {
755+ const auto id = ::Microsoft::Console::Utils::GuidFromString (str.c_str ());
756+ args.SessionId (id);
757+ }
758+ catch (...)
759+ {
760+ // Invalid GUID provided - silently ignore similar to how invalid
761+ // tab colors are handled.
762+ }
741763 }
742764
743765 if (*subcommand.startingDirectoryOption )
0 commit comments