Commit 8aeb2a2
[Tables] Fix RequestFailedException contract in GetEntityAsync/GetEntityIfExistsAsync when response body is missing or malformed (Azure#58305)
* Initial plan
* Fix ArgumentNullException in GetEntityAsync/GetEntityIfExistsAsync when ContentStream is null
Add null check for response.ContentStream before calling ResponseToDictionary
in GetEntityInternalAsync. When ContentStream is null on a non-404 response,
throw RequestFailedException instead of letting ArgumentNullException bubble up
from JsonDocument.Parse.
Add regression tests and changelog entry.
Fixes Azure#58303
Agent-Logs-Url: https://github.com/Azure/azure-sdk-for-net/sessions/294e65c4-fa6f-4aba-b3f7-eace4eea30cf
Co-authored-by: jsquire <913445+jsquire@users.noreply.github.com>
* Use await in ThrowsAsync assertions in new tests
Agent-Logs-Url: https://github.com/Azure/azure-sdk-for-net/sessions/294e65c4-fa6f-4aba-b3f7-eace4eea30cf
Co-authored-by: jsquire <913445+jsquire@users.noreply.github.com>
* Set ContentStream to empty MemoryStream before throwing RequestFailedException
When response.ContentStream is null, assign an empty MemoryStream before
throwing RequestFailedException(response). This ensures:
1. The exception message includes the HTTP status code and reason phrase
(context for callers to diagnose the error)
2. GetRawResponse().ContentStream is non-null after catching the exception
(protects callers from NullReferenceException when reading raw response)
Also update NullContentStreamMockResponse mock to properly propagate the
setter so the regression tests can verify that ContentStream is non-null
on the thrown exception's raw response.
Agent-Logs-Url: https://github.com/Azure/azure-sdk-for-net/sessions/b5206032-2deb-4830-a756-5f1d4f5590a4
Co-authored-by: jsquire <913445+jsquire@users.noreply.github.com>
* Use explicit message in RequestFailedException when ContentStream is null
Replace RequestFailedException(response) with RequestFailedException(status, message)
to avoid the misleading "Service request succeeded." text that was produced
when ContentStream was null on a 200 OK response.
The new message explicitly says "Response body was null or empty. HTTP {status} ({reason})"
which clearly communicates what went wrong and includes the status code for context.
Also simplify NullContentStreamMockResponse back to a read-only getter,
and update test assertions to verify the status code and message content.
Agent-Logs-Url: https://github.com/Azure/azure-sdk-for-net/sessions/1362d0e0-26c9-4cd8-8fa8-1bac42cdf036
Co-authored-by: jsquire <913445+jsquire@users.noreply.github.com>
* Apply suggestion from @jsquire
* Update sdk/tables/Azure.Data.Tables/src/TableClient.cs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Handle empty/malformed ContentStream: catch JsonException and rethrow as RequestFailedException
The null ContentStream check only covered one scenario. An empty or malformed
(but non-null) stream causes JsonDocument.Parse to throw JsonException, which
would leak an internal parsing exception to callers.
Fix: wrap SerializationHelpers.ResponseToDictionary in a try/catch for
JsonException and rethrow as RequestFailedException with a descriptive message.
Also:
- Add System.Text.Json using for JsonException
- Add 4 regression tests covering empty MemoryStream scenario
- Update CHANGELOG wording to match the null ContentStream scope of the fix
Agent-Logs-Url: https://github.com/Azure/azure-sdk-for-net/sessions/4598458f-3f67-467c-97d0-2afbb1022424
Co-authored-by: jsquire <913445+jsquire@users.noreply.github.com>
* Eagerly detect empty ContentStream at the null guard (L797)
Agent-Logs-Url: https://github.com/Azure/azure-sdk-for-net/sessions/9108391f-f04d-409a-bd1c-6c2d9ff906f7
Co-authored-by: jsquire <913445+jsquire@users.noreply.github.com>
* De-duplicate RequestFailedException throws into a single catch block
Agent-Logs-Url: https://github.com/Azure/azure-sdk-for-net/sessions/67365fc6-8da0-4535-a223-9dcd09736569
Co-authored-by: jsquire <913445+jsquire@users.noreply.github.com>
* Restore 'or malformed' in RequestFailedException message
Agent-Logs-Url: https://github.com/Azure/azure-sdk-for-net/sessions/123bdfc7-8417-4dc3-a70a-962308357eab
Co-authored-by: jsquire <913445+jsquire@users.noreply.github.com>
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jsquire <913445+jsquire@users.noreply.github.com>
Co-authored-by: Jesse Squire <jesse.squire@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>1 parent 1f9b8a6 commit 8aeb2a2
3 files changed
Lines changed: 104 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
16 | 19 | | |
17 | 20 | | |
18 | 21 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
792 | 793 | | |
793 | 794 | | |
794 | 795 | | |
795 | | - | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
796 | 799 | | |
797 | | - | |
798 | | - | |
799 | | - | |
| 800 | + | |
800 | 801 | | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
801 | 812 | | |
802 | 813 | | |
803 | 814 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
785 | 785 | | |
786 | 786 | | |
787 | 787 | | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
788 | 860 | | |
789 | 861 | | |
790 | 862 | | |
| |||
801 | 873 | | |
802 | 874 | | |
803 | 875 | | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
804 | 890 | | |
805 | 891 | | |
806 | 892 | | |
| |||
0 commit comments