Skip to content

Preserve RequestFailedException what() when copying - #7484

Open
Joel Town Road (hippi345) wants to merge 1 commit into
Azure:mainfrom
hippi345:fix/7272-exception-copy-message
Open

Joel Town Road (hippi345) wants to merge 1 commit into
Azure:mainfrom
hippi345:fix/7272-exception-copy-message

Conversation

@hippi345

Copy link
Copy Markdown

Pull Request Checklist

Please leverage this checklist as a reminder to address commonly occurring feedback when submitting a pull request to make sure your PR can be reviewed quickly:

See the detailed list in the contributing guide.

  • C++ Guidelines
  • Doxygen docs
  • Unit tests
  • No unwanted commits/changes
  • Descriptive title/description
    • PR is single purpose
    • Related issue listed
  • Comments in source
  • No typos
  • Update changelog
  • Not work-in-progress
  • External references or docs updated
  • Self review of PR done
  • Any breaking changes?

Problem

Azure::Core::RequestFailedException's copy constructor initialized std::runtime_error from other.Message instead of other.what(). Those strings are not the same:

  • The string constructor sets what() and leaves Message empty.
  • The raw-response constructor sets what() to the HTTP status/reason text and sets Message to the service message field (for example "JT").

A copy therefore replaced what() with Message. Derived types such as Azure::Storage::StorageException inherit this constructor and have the same defect. StorageException does not declare its own copy constructor, so no storage-side change was required.

Fixes #7272

Change

In RequestFailedException(const RequestFailedException&), initialize the base with other.what() so a copy preserves what() and Message exactly. Copy/move assignment operators remain = delete. There are no public API changes.

Because the copy constructor is inline in an installed header, consumers linking a prebuilt binary must rebuild to pick up the fix.

Testing

Added RequestFailedException.CopyPreservesWhatAndMessage in sdk/core/azure-core/test/ut/exception_test.cpp. It builds a RequestFailedException from a RawResponse with a JSON error body (message: "JT"), copies it, and asserts copy.what() and copy.Message equal the original.

Before (unmodified copy constructor) — gtest assertion failure, not a compile error:

[ RUN      ] RequestFailedException.CopyPreservesWhatAndMessage
/workspace/sdk/core/azure-core/test/ut/exception_test.cpp:67: Failure
Expected equality of these values:
  std::string(copy.what())
    Which is: "JT"
  std::string(exception.what())
    Which is: "Received an HTTP unsuccessful status code: 503 Reason: retry please :"
[  FAILED  ] RequestFailedException.CopyPreservesWhatAndMessage (0 ms)

[==========] 4 tests from 1 test suite ran. (0 ms total)
[  PASSED  ] 3 tests.
[  FAILED  ] 1 test, listed below:
[  FAILED  ] RequestFailedException.CopyPreservesWhatAndMessage

After:

[==========] Running 4 tests from 1 test suite.
[----------] 4 tests from RequestFailedException
[ RUN      ] RequestFailedException.JSONError
[       OK ] RequestFailedException.JSONError (0 ms)
[ RUN      ] RequestFailedException.CopyPreservesWhatAndMessage
[       OK ] RequestFailedException.CopyPreservesWhatAndMessage (0 ms)
[ RUN      ] RequestFailedException.JSONErrorNoError
[       OK ] RequestFailedException.JSONErrorNoError (0 ms)
[ RUN      ] RequestFailedException.EmptyValues
[       OK ] RequestFailedException.EmptyValues (0 ms)
[==========] 4 tests from 1 test suite ran. (0 ms total)
[  PASSED  ] 4 tests.

Full azure-core-test binary: 368 tests ran, 330 passed, remaining skipped/disabled (live transport). ctest -R azure-core from sdk/core/azure-core/build/test/ut: 373 discovered tests, exception tests passed; the only CTest failures were pre-existing *_NOT_BUILT placeholders for binaries not built in this targeted azure-core-test compile.

This change was prepared with AI assistance and reviewed by the author.

Initialize the copy constructor from other.what() instead of
other.Message so copies keep the original explanatory string.
@github-actions github-actions Bot added Azure.Core Community Contribution Community members are working on the issue customer-reported Issues that are reported by GitHub users external to the Azure organization. labels Oct 17, 2026
@github-actions

Copy link
Copy Markdown

Thank you for your contribution Joel Town Road (@hippi345)! We will review the pull request and get back to you soon.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).
8 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI 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.

🟢 Approval recommended

The focused fix addresses the reported defect with regression coverage and no identified blocking issues.

No open issues 🎉

What changed in this PR

Fixes #7272 by preserving RequestFailedException::what() when copying, including inherited behavior in derived exceptions.

Changes:

  • Initializes the copied exception’s base from other.what().
  • Adds regression coverage for preserving diagnostics and Message.
  • Documents the fix and consumer rebuild requirement.
File Description
sdk/​core/​azure-core/​test/​ut/​exception_test.cpp Tests preservation of what() and Message after copying.
sdk/​core/​azure-core/​inc/​azure/​core/​exception.hpp Corrects the copy constructor’s base initialization.
sdk/​core/​azure-core/​CHANGELOG.md Records the fix and rebuild requirement.

Review effort: Balanced

This branch has not been deployed

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

Labels

Azure.Core Community Contribution Community members are working on the issue customer-reported Issues that are reported by GitHub users external to the Azure organization.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RequestFailedException loses its message when it is copied

2 participants