Skip to content

Conversation

vincenttran-msft
Copy link
Member

@vincenttran-msft vincenttran-msft commented Sep 16, 2025

stdout for test_storage_error_model:

running 1 test
Standard Error Message: 404: BlobNotFoundThe specified blob does not exist.
RequestId:f65c5ab0-601e-008d-677c-2ec0a1000000
Time:2025-09-26T00:29:56.3906662Z

Http Status Code: 404
Storage Error Code: BlobNotFound
Response Headers:
"x-ms-client-request-id": "3b2dec8d-758b-45fd-adad-ba81c0d761b9"
"content-length": "215"
"server": "Microsoft-HTTPAPI/2.0"
"x-ms-version": "2025-11-05"
"content-type": "application/xml"
"date": "Fri, 26 Sep 2025 00:29:56 GMT"
"x-ms-request-id": "f65c5ab0-601e-008d-677c-2ec0a1000000"
"x-ms-error-code": "BlobNotFound"
"x-recording-mode": "record"

test test_storage_error_model ... ok

@github-actions github-actions bot added the Storage Storage Service (Queues, Blobs, Files) label Sep 16, 2025
@vincenttran-msft
Copy link
Member Author

cc: @heaths Heath, any pointers here on how to proceed with accessing the raw response on an Error response. Thanks!

@vincenttran-msft vincenttran-msft changed the title [Storage] Storage Error Handling WIP [Storage] Add StorageError model type Sep 26, 2025
Comment on lines +156 to +168
impl std::fmt::Display for StorageError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(f, "Standard Error Message: {}\n", self.message)?;
writeln!(f, "Http Status Code: {}", self.status_code)?;
writeln!(f, "Storage Error Code: {}", self.error_code)?;
writeln!(f, "Response Headers:")?;

for (name, value) in self.headers.iter() {
writeln!(f, " \"{}\": \"{}\"", name.as_str(), value.as_str())?;
}

Ok(())
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Looking for some feedback here on how we want to implement the display. This is sort of what I came up with, and to re-iterate this is what currently comes out:

Standard Error Message: 404: BlobNotFoundThe specified blob does not exist.
RequestId:f65c5ab0-601e-008d-677c-2ec0a1000000
Time:2025-09-26T00:29:56.3906662Z

Http Status Code: 404
Storage Error Code: BlobNotFound
Response Headers:
"x-ms-client-request-id": "3b2dec8d-758b-45fd-adad-ba81c0d761b9"
"content-length": "215"
"server": "Microsoft-HTTPAPI/2.0"
"x-ms-version": "2025-11-05"
"content-type": "application/xml"
"date": "Fri, 26 Sep 2025 00:29:56 GMT"
"x-ms-request-id": "f65c5ab0-601e-008d-677c-2ec0a1000000"
"x-ms-error-code": "BlobNotFound"
"x-recording-mode": "record"

Ideally I want to eliminate writeln!(f, "Standard Error Message: {}\n", self.message)?; and I currently just have it there to show the current functionality of azure_core::Error.to_string().

I think we want to be able to extract just the message and surface that since we have all the other displayed elsewhere.
i.e. The specified blob does not exist..

Copy link
Member

Choose a reason for hiding this comment

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

  1. probably remove the quotations on headers as that's not generally how they're rendered.
  2. would this end up in logs? if so we probably want to hook in whatever we're using to allow/redact specific headers

Copy link
Member

Choose a reason for hiding this comment

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

Headers should be sanitized. (Error bodies aren't supposed to contain PII.) @LarryOsterman added a sanitize function you should use.

I also recommend proper grammar e.g., "HTTP" instead of "Http", etc. Order of fields should make sense. In .NET, it was:

{HTTP status code} {HTTP error code}
{Headers}

{Error response body}

Basically, formatted close to an actual HTTP response like many devs are used to.

Copy link
Member

Choose a reason for hiding this comment

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

And before you go off and do this, we should discuss whether to change the Display implementation for azure_core::Error. Is this the only reason you're making StorageError? We already support formatting for display.

Copy link

API Change Check

APIView identified API level changes in this PR and created the following API reviews

azure_storage_blob

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Storage Storage Service (Queues, Blobs, Files)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants