Skip to content

Support width and alignment in std::exception formatter - #4860

Open
s3yato wants to merge 1 commit into
fmtlib:mainfrom
s3yato:feature/exception-formatter-align
Open

Support width and alignment in std::exception formatter#4860
s3yato wants to merge 1 commit into
fmtlib:mainfrom
s3yato:feature/exception-formatter-align

Conversation

@s3yato

@s3yato s3yato commented Jul 20, 2026

Copy link
Copy Markdown

The formatter for std::exception (and std::exception_ptr) previously accepted only the optional 't' type-name specifier, so standard fill, align and width specifiers were rejected with "unknown format specifier". This made it impossible to pad or align exception messages, e.g. when laying them out in a log column.

Parse the standard fill/align/width specifiers (as the std::filesystem:: path formatter already does) and apply them when writing the message. Dynamic width ({:{}}) and the 'none'/'unknown exception' cases for exception_ptr are handled too. Existing behavior ({}, {:t}, nested exception unwinding) is unchanged.

@s3yato
s3yato requested a review from vitaut as a code owner July 20, 2026 14:26
@s3yato
s3yato force-pushed the feature/exception-formatter-align branch from da270bc to b059132 Compare July 20, 2026 14:29

@vitaut vitaut left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. Mostly looks good but let's avoid writing to an intermediate buffer for the common case of no width.

The formatter for std::exception (and std::exception_ptr) previously
accepted only the optional 't' type-name specifier, so standard fill,
align and width specifiers were rejected with "unknown format
specifier". This made it impossible to pad or align exception messages,
e.g. when laying them out in a log column.

Parse the standard fill/align/width specifiers (as the std::filesystem::
path formatter already does) and apply them when writing the message.
Dynamic width ({:{}}) and the 'none'/'unknown exception' cases for
exception_ptr are handled too. Existing behavior ({}, {:t}, nested
exception unwinding) is unchanged.
@s3yato
s3yato force-pushed the feature/exception-formatter-align branch from b059132 to 6eb553d Compare August 4, 2026 11:32
@s3yato

s3yato commented Aug 4, 2026

Copy link
Copy Markdown
Author

Good catch — added a fast path that writes directly to the output when no width is requested; only the padded case allocates an intermediate buffer now. Dynamic width ({:{}}) still goes through the buffered path. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants