@@ -395,8 +395,8 @@ pub struct AuthorizationError {
395395 pub login_url : Option < Url > ,
396396 /// Specific reason indicating what failed
397397 reason : AuthorizationErrorReason ,
398- /// Should the _TOKEN environment variable name be included when displaying this error?
399- display_token_env_help : bool ,
398+ /// Should `cargo login` and the ` _TOKEN` env var be included when displaying this error?
399+ supports_cargo_token_credential_provider : bool ,
400400}
401401
402402impl AuthorizationError {
@@ -409,15 +409,16 @@ impl AuthorizationError {
409409 // Only display the _TOKEN environment variable suggestion if the `cargo:token` credential
410410 // provider is available for the source. Otherwise setting the environment variable will
411411 // have no effect.
412- let display_token_env_help = credential_provider ( gctx, & sid, false , false ) ?
413- . iter ( )
414- . any ( |p| p. first ( ) . map ( String :: as_str) == Some ( "cargo:token" ) ) ;
412+ let supports_cargo_token_credential_provider =
413+ credential_provider ( gctx, & sid, false , false ) ?
414+ . iter ( )
415+ . any ( |p| p. first ( ) . map ( String :: as_str) == Some ( "cargo:token" ) ) ;
415416 Ok ( AuthorizationError {
416417 sid,
417418 default_registry : gctx. default_registry ( ) ?,
418419 login_url,
419420 reason,
420- display_token_env_help ,
421+ supports_cargo_token_credential_provider ,
421422 } )
422423 }
423424}
@@ -432,20 +433,30 @@ impl fmt::Display for AuthorizationError {
432433 ""
433434 } ;
434435 write ! ( f, "{}, please run `cargo login{args}`" , self . reason) ?;
435- if self . display_token_env_help {
436+ if self . supports_cargo_token_credential_provider {
436437 write ! ( f, "\n or use environment variable CARGO_REGISTRY_TOKEN" ) ?;
437438 }
438439 Ok ( ( ) )
439440 } else if let Some ( name) = self . sid . alt_registry_key ( ) {
440- let key = ConfigKey :: from_str ( & format ! ( "registries.{name}.token" ) ) ;
441441 write ! (
442442 f,
443- "{} for `{}`, please run `cargo login --registry {name}` " ,
443+ "{} for `{}`" ,
444444 self . reason,
445- self . sid. display_registry_name( ) ,
445+ self . sid. display_registry_name( )
446446 ) ?;
447- if self . display_token_env_help {
448- write ! ( f, "\n or use environment variable {}" , key. as_env_key( ) ) ?;
447+ if self . supports_cargo_token_credential_provider {
448+ let key = ConfigKey :: from_str ( & format ! ( "registries.{name}.token" ) ) ;
449+ write ! (
450+ f,
451+ ", please run `cargo login --registry {name}`\n \
452+ or use environment variable {}",
453+ key. as_env_key( )
454+ ) ?;
455+ } else {
456+ write ! (
457+ f,
458+ "\n You may need to log in using this registry's credential provider"
459+ ) ?;
449460 }
450461 Ok ( ( ) )
451462 } else if self . reason == AuthorizationErrorReason :: TokenMissing {
0 commit comments