Skip to content

migrate azure_identity to azure_core::error::Error #781

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jun 7, 2022

Conversation

ctaggart
Copy link
Contributor

@ctaggart ctaggart commented Jun 4, 2022

Changes:

  • Removes thiserror errors & replaces with azure_core::error::Error
  • Removes identity::TokenCredential
  • get_token switched to azure_core::error::Error
  • changes Error::with_message to accept a FnOnce like ResultExt::with_context.
  • Adds Error::message, similar to ResultExt::context.
  • refresh_token error handling now checks response status

@ctaggart
Copy link
Contributor Author

ctaggart commented Jun 5, 2022

I had to show myself what format! does under the covers.

fn calc(s: impl Into<String>){
    s.into();
}

fn main() {
    calc(format!("Hello, world!"));
}

output from cargo expand:

#![feature(prelude_import)]
#[prelude_import]
use std::prelude::rust_2021::*;
#[macro_use]
extern crate std;
fn calc(s: impl Into<String>) {
    s.into();
}
fn main() {
    calc({
        let res = ::alloc::fmt::format(::core::fmt::Arguments::new_v1(&["Hello, world!"], &[]));
        res
    });
}

So yes, it is better to use a || format!.

@@ -103,7 +109,7 @@ impl Error {
}

/// Create an `Error` based on an error kind and some sort of message
pub fn with_message<C>(kind: ErrorKind, message: C) -> Self
pub fn message<C>(kind: ErrorKind, message: C) -> Self
Copy link
Contributor Author

Choose a reason for hiding this comment

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

More similar with ResultExt::context

@@ -115,6 +121,21 @@ impl Error {
}
}

/// Creates an `Error` based on an error kind and formatted message
pub fn with_message<F, C>(kind: ErrorKind, message: F) -> Self
Copy link
Contributor Author

@ctaggart ctaggart Jun 5, 2022

Choose a reason for hiding this comment

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

Takes a function like ResultExt::with_context. What about naming message_fn or event messagef?

@ctaggart ctaggart marked this pull request as ready for review June 5, 2022 17:25
@johnbatty
Copy link
Contributor

I'm happy with the current naming. The context/with_context naming matches that of the corresponding anyhow functions, so this does have the benefit of being familiar to existing anyhow users.

Copy link
Contributor

@johnbatty johnbatty left a comment

Choose a reason for hiding this comment

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

Mainly questions/clarifications about ErrorKind usage.

Copy link
Contributor

@johnbatty johnbatty left a comment

Choose a reason for hiding this comment

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

More ErrorKind suggestions... In my previous review I only gave a few as I wanted to know whether you agreed with the suggested changes. These cover the whole PR. Again, all are just suggestions so take or leave as you wish.

@cataggar cataggar requested a review from johnbatty June 7, 2022 12:49
Copy link
Contributor

@johnbatty johnbatty left a comment

Choose a reason for hiding this comment

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

Looks good - approved.

@cataggar cataggar merged commit fb93e37 into Azure:main Jun 7, 2022
@ctaggart ctaggart deleted the identity-errors branch June 16, 2022 00:07
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.

3 participants