fix tinyformat#78793
Open
wanghuancoder wants to merge 3 commits intoPaddlePaddle:developfrom
Open
Conversation
|
你的PR提交成功,感谢你对开源项目的贡献! |
… fix_tinyformat
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adjusts Paddle’s bundled tinyformat-based printf utilities to avoid crashing (assert/abort) when the format string’s conversion specifiers don’t match the provided arguments, aiming to preserve more useful PADDLE_ENFORCE error context.
Changes:
- Replace tinyformat’s assert-based error path with a thrown
detail::FormatError. - Add catch/fallback behavior in
paddle::string::Fprintf/Sprintfto output/return the raw format string on format errors.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| paddle/utils/string/tinyformat/tinyformat.h | Replaces TINYFORMAT_ERROR assert handling with detail::FormatError exceptions thrown on format errors. |
| paddle/utils/string/printf.h | Wraps tinyformat formatting calls with try/catch to fall back to raw format strings when a FormatError is raised. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "tinyformat: Cannot convert from argument type to " | ||
| "integer for use as variable width or precision"); | ||
| throw FormatError(); | ||
| return 0; |
| TINYFORMAT_ERROR( | ||
| "tinyformat: Not enough conversion specifiers in format string"); | ||
| throw FormatError(); | ||
| return fmtStart; |
| // Check args remain after reading any variable width/precision | ||
| TINYFORMAT_ERROR("tinyformat: Not enough format arguments"); | ||
| throw FormatError(); | ||
| return; |
| void Fprintf(std::ostream& out, const char* fmt, const Args&... args) { | ||
| tinyformat::vformat(out, fmt, tinyformat::makeFormatList(args...)); | ||
| try { | ||
| tinyformat::vformat(out, fmt, tinyformat::makeFormatList(args...)); |
Comment on lines
101
to
+108
| std::string Sprintf(const char* fmt, const Args&... args) { | ||
| std::ostringstream oss; | ||
| Fprintf(oss, fmt, args...); | ||
| return oss.str(); | ||
| try { | ||
| std::ostringstream oss; | ||
| Fprintf(oss, fmt, args...); | ||
| return oss.str(); | ||
| } catch (const tinyformat::detail::FormatError&) { | ||
| return fmt; | ||
| } |
| void Fprintf(std::ostream& out, const char* fmt, const Args&... args) { | ||
| tinyformat::vformat(out, fmt, tinyformat::makeFormatList(args...)); | ||
| try { | ||
| tinyformat::vformat(out, fmt, tinyformat::makeFormatList(args...)); |
Comment on lines
+122
to
+123
| // Error handling: Format errors throw detail::FormatError, which is caught | ||
| // at the public API level to fall back to the raw format string. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Category
Execute Infrastructure
PR Types
Improvements
Description
删除tinyformat里的assert,防止PADDLE_ENFORCE %个数和变量不匹配时,崩溃在assert上而没有提供PADDLE_ENFORCE更有价值的信息。
业务上发生了这种情况。但不可解释的是,assert只在DEBUG编译下才生效,为何发版的包assert会生效暂时没有找到。
通过如下方式复现问题
是否引起精度变化
否