Skip to content

[CODE HEALTH] Fix clang-tidy bugprone-exception-escape warnings in API#3964

Draft
dbarker wants to merge 4 commits intoopen-telemetry:mainfrom
dbarker:fix_clangtidy_exception_escape_in_api
Draft

[CODE HEALTH] Fix clang-tidy bugprone-exception-escape warnings in API#3964
dbarker wants to merge 4 commits intoopen-telemetry:mainfrom
dbarker:fix_clangtidy_exception_escape_in_api

Conversation

@dbarker
Copy link
Copy Markdown
Member

@dbarker dbarker commented Apr 1, 2026

Contributes to #2053

Changes

  • replace nostd::get with the noexcept nostd::get_if in API
  • Add macros to support try/catch when compiling with and without exceptions
  • Add macro for unreachable code paths
  • Add unit test coverage for cases with string_view, string_util, and trace/context.
  • Fixes the following warnings:

bugprone-exception-escape (5 warnings)

File Line Message
opentelemetry-cpp/api/include/opentelemetry/trace/context.h 26 an exception may be thrown in function 'IsRootSpan' which should not throw exceptions
opentelemetry-cpp/api/include/opentelemetry/trace/trace_state.h 55 an exception may be thrown in function 'FromHeader' which should not throw exceptions
opentelemetry-cpp/api/include/opentelemetry/trace/trace_state.h 118 an exception may be thrown in function 'Get' which should not throw exceptions
opentelemetry-cpp/api/include/opentelemetry/trace/trace_state.h 138 an exception may be thrown in function 'Set' which should not throw exceptions
opentelemetry-cpp/api/include/opentelemetry/trace/trace_state.h 172 an exception may be thrown in function 'Delete' which should not throw exceptions

cppcoreguidelines-missing-std-forward (1 warnings)

File Line Message
opentelemetry-cpp/api/include/opentelemetry/nostd/function_ref.h 81 forwarding reference parameter 'f' is never forwarded inside the function body

For significant contributions please make sure you have completed the following items:

  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 1, 2026

Codecov Report

❌ Patch coverage is 85.50725% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.05%. Comparing base (8aae05f) to head (0b6d984).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
api/include/opentelemetry/trace/trace_state.h 84.32% 8 Missing ⚠️
api/include/opentelemetry/plugin/detail/utility.h 50.00% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3964      +/-   ##
==========================================
- Coverage   90.12%   90.05%   -0.06%     
==========================================
  Files         227      227              
  Lines        7261     7273      +12     
==========================================
+ Hits         6543     6549       +6     
- Misses        718      724       +6     
Files with missing lines Coverage Δ
...pi/include/opentelemetry/baggage/baggage_context.h 100.00% <100.00%> (ø)
api/include/opentelemetry/common/string_util.h 100.00% <100.00%> (ø)
api/include/opentelemetry/nostd/function_ref.h 77.78% <ø> (ø)
api/include/opentelemetry/nostd/string_view.h 98.15% <ø> (ø)
api/include/opentelemetry/nostd/variant.h 66.67% <ø> (ø)
api/include/opentelemetry/trace/context.h 100.00% <100.00%> (+8.34%) ⬆️
api/include/opentelemetry/trace/tracer.h 100.00% <100.00%> (ø)
api/include/opentelemetry/plugin/detail/utility.h 50.00% <50.00%> (ø)
api/include/opentelemetry/trace/trace_state.h 90.33% <84.32%> (-7.29%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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