Skip to content

Commit

Permalink
Make the TerminalApi exception handler less garrulous (#10901)
Browse files Browse the repository at this point in the history
## Summary of the Pull Request

Apparently the exception handler in TerminalApi is far too talkative. We're apparently throwing in `TerminalApi::CursorLineFeed` way too often, and that's caused an internal bug to be filed on us.

This represents making the event less talkative, but doesn't actually fix the bug. It's just easier to get the OS bug cleared out quick this way. 

## References
* MSFT:33310649

## PR Checklist
* [x] Fixes the **A** portion of #10882, which closes MSFT:33310649
* [x] I work here
* [n/a] Tests added/passed
* [n/a] Requires documentation to be updated
  • Loading branch information
zadjii-msft authored and DHowett committed Aug 25, 2021
1 parent cc215ce commit 68c54bf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
34 changes: 17 additions & 17 deletions src/cascadia/TerminalCore/TerminalApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ try
_WriteBuffer(stringView);
return true;
}
CATCH_LOG_RETURN_FALSE()
CATCH_RETURN_FALSE()

bool Terminal::ExecuteChar(wchar_t wch) noexcept
try
{
_WriteBuffer({ &wch, 1 });
return true;
}
CATCH_LOG_RETURN_FALSE()
CATCH_RETURN_FALSE()

TextAttribute Terminal::GetTextAttributes() const noexcept
{
Expand Down Expand Up @@ -54,7 +54,7 @@ try

return true;
}
CATCH_LOG_RETURN_FALSE()
CATCH_RETURN_FALSE()

COORD Terminal::GetCursorPosition() noexcept
{
Expand All @@ -75,7 +75,7 @@ try
_buffer->GetCursor().SetColor(color);
return true;
}
CATCH_LOG_RETURN_FALSE()
CATCH_RETURN_FALSE()

// Method Description:
// - Moves the cursor down one line, and possibly also to the leftmost column.
Expand All @@ -101,7 +101,7 @@ try

return true;
}
CATCH_LOG_RETURN_FALSE()
CATCH_RETURN_FALSE()

// Method Description:
// - deletes count characters starting from the cursor's current position
Expand Down Expand Up @@ -150,7 +150,7 @@ try

return true;
}
CATCH_LOG_RETURN_FALSE()
CATCH_RETURN_FALSE()

// Method Description:
// - Inserts count spaces starting from the cursor's current position, moving over the existing text
Expand Down Expand Up @@ -205,7 +205,7 @@ try

return true;
}
CATCH_LOG_RETURN_FALSE()
CATCH_RETURN_FALSE()

bool Terminal::EraseCharacters(const size_t numChars) noexcept
try
Expand All @@ -218,7 +218,7 @@ try
_buffer->Write(eraseIter, absoluteCursorPos);
return true;
}
CATCH_LOG_RETURN_FALSE()
CATCH_RETURN_FALSE()

// Method description:
// - erases a line of text, either from
Expand Down Expand Up @@ -264,7 +264,7 @@ try
_buffer->Write(eraseIter, startPos, false);
return true;
}
CATCH_LOG_RETURN_FALSE()
CATCH_RETURN_FALSE()

// Method description:
// - erases text in the buffer in two ways depending on erase type
Expand Down Expand Up @@ -348,15 +348,15 @@ try

return true;
}
CATCH_LOG_RETURN_FALSE()
CATCH_RETURN_FALSE()

bool Terminal::WarningBell() noexcept
try
{
_pfnWarningBell();
return true;
}
CATCH_LOG_RETURN_FALSE()
CATCH_RETURN_FALSE()

bool Terminal::SetWindowTitle(std::wstring_view title) noexcept
try
Expand All @@ -368,7 +368,7 @@ try
}
return true;
}
CATCH_LOG_RETURN_FALSE()
CATCH_RETURN_FALSE()

// Method Description:
// - Updates the value in the colortable at index tableIndex to the new color
Expand All @@ -387,7 +387,7 @@ try
_buffer->GetRenderTarget().TriggerRedrawAll();
return true;
}
CATCH_LOG_RETURN_FALSE()
CATCH_RETURN_FALSE()

// Method Description:
// - Sets the cursor style to the given style.
Expand Down Expand Up @@ -457,7 +457,7 @@ try
_buffer->GetRenderTarget().TriggerRedrawAll();
return true;
}
CATCH_LOG_RETURN_FALSE()
CATCH_RETURN_FALSE()

// Method Description:
// - Updates the default background color from a COLORREF, format 0x00BBGGRR.
Expand All @@ -475,7 +475,7 @@ try
_buffer->GetRenderTarget().TriggerRedrawAll();
return true;
}
CATCH_LOG_RETURN_FALSE()
CATCH_RETURN_FALSE()

til::color Terminal::GetDefaultBackground() const noexcept
{
Expand Down Expand Up @@ -509,7 +509,7 @@ try
_buffer->GetRenderTarget().TriggerRedrawAll();
return true;
}
CATCH_LOG_RETURN_FALSE()
CATCH_RETURN_FALSE()

bool Terminal::EnableVT200MouseMode(const bool enabled) noexcept
{
Expand Down Expand Up @@ -591,7 +591,7 @@ try

return true;
}
CATCH_LOG_RETURN_FALSE()
CATCH_RETURN_FALSE()

// Method Description:
// - Updates the buffer's current text attributes to start a hyperlink
Expand Down
11 changes: 10 additions & 1 deletion src/inc/til.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ namespace til // Terminal Implementation Library. Also: "Today I Learned"
} \
} while (0, 0)

// Due to a bug (DevDiv 441931), Warning 4297 (function marked noexcept throws exception) is detected even when the throwing code is unreachable, such as the end of scope after a return, in function-level catch.
// Due to a bug (DevDiv 441931), Warning 4297 (function marked noexcept throws
// exception) is detected even when the throwing code is unreachable, such as
// the end of scope after a return, in function-level catch.
#define CATCH_LOG_RETURN_FALSE() \
catch (...) \
{ \
Expand All @@ -98,6 +100,13 @@ namespace til // Terminal Implementation Library. Also: "Today I Learned"
return false; \
}

// This is like the above, but doesn't log any messages. This is for GH#10882.
#define CATCH_RETURN_FALSE() \
catch (...) \
{ \
return false; \
}

// MultiByteToWideChar has a bug in it where it can return 0 and then not set last error.
// WIL has a fit if the last error is 0 when a bool false is returned.
// This macro doesn't have a fit. It just reports E_UNEXPECTED instead.
Expand Down

0 comments on commit 68c54bf

Please sign in to comment.