Skip to content

[common] Add support for std::optional in error messages#78521

Merged
SigureMo merged 3 commits intoPaddlePaddle:developfrom
gouzil:feat/PD_CHECK_support_optional
Apr 4, 2026
Merged

[common] Add support for std::optional in error messages#78521
SigureMo merged 3 commits intoPaddlePaddle:developfrom
gouzil:feat/PD_CHECK_support_optional

Conversation

@gouzil
Copy link
Copy Markdown
Member

@gouzil gouzil commented Mar 29, 2026

PR Category

Execute Infrastructure

PR Types

Devs

Description

在减少 paddlecodec diff 时发现,PD_CHECK 不支持 std::optional 相关输出

相关链接

cc: @ShigureNyako

是否引起精度变化

Copilot AI review requested due to automatic review settings March 29, 2026 09:29
@paddle-bot
Copy link
Copy Markdown

paddle-bot Bot commented Mar 29, 2026

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@paddle-bot paddle-bot Bot added the contributor External developers label Mar 29, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves paddle/common/exception.h’s ErrorMessage builder (used by PD_CHECK / PD_THROW) to support formatting std::optional<T> values, so optional values can appear in error messages without compilation failures.

Changes:

  • Add a build_string(const std::optional<T>&) overload in common::ErrorMessage to render nullopt or the contained value.
  • Add C++ unit tests validating ErrorMessage formatting for std::optional and that PD_CHECK exceptions include optional content.
  • Register the new test in test/cpp/utils/CMakeLists.txt.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
paddle/common/exception.h Adds std::optional formatting support inside ErrorMessage.
test/cpp/utils/exception_test.cc New tests covering optional formatting + PD_CHECK throwing/message behavior.
test/cpp/utils/CMakeLists.txt Adds exception_test target so the new tests run in CI.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@gouzil
Copy link
Copy Markdown
Member Author

gouzil commented Mar 30, 2026

@ShigureNyako 帮我看看 https://github.com/PaddlePaddle/Paddle/actions/runs/23706074064/job/69071406580?pr=78521 ,看起来 Linux-NPU 并没有使用 c++ 17 编译

@gouzil gouzil requested a review from SigureMo March 30, 2026 01:18
@gouzil
Copy link
Copy Markdown
Member Author

gouzil commented Apr 3, 2026

@ShigureNyako 排查一下 Coverage 为什么编译的那么慢

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (develop@8309551). Learn more about missing BASE report.

Additional details and impacted files
@@             Coverage Diff             @@
##             develop    #78521   +/-   ##
===========================================
  Coverage           ?   100.00%           
===========================================
  Files              ?         1           
  Lines              ?         4           
  Branches           ?         0           
===========================================
  Hits               ?         4           
  Misses             ?         0           
  Partials           ?         0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@SigureMo SigureMo changed the title [common] Add support for std::optional in error messages [common] Add support for std::optional in error messages Apr 4, 2026
@SigureMo
Copy link
Copy Markdown
Member

SigureMo commented Apr 4, 2026

DCU 的 build 机器和其他的不一样,好像没有挂载跨机共享的 CFS,所以 cache 是每个机器独立的,这个 PR merge 后可能会有几个 PR 的 DCU build 会超时挂掉,待 cache 在每台机器上均匀分布之后才能恢复正常……

@SigureMo SigureMo merged commit 3bb286a into PaddlePaddle:develop Apr 4, 2026
228 of 242 checks passed
@SigureMo SigureMo deleted the feat/PD_CHECK_support_optional branch April 4, 2026 20:48
liuhao2638 pushed a commit to liuhao2638/Paddle that referenced this pull request Apr 7, 2026
YuhanXu pushed a commit to YuhanXu/Paddle that referenced this pull request Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor External developers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants