@@ -395,8 +395,8 @@ pub struct AuthorizationError {
395
395
pub login_url : Option < Url > ,
396
396
/// Specific reason indicating what failed
397
397
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 ,
400
400
}
401
401
402
402
impl AuthorizationError {
@@ -409,15 +409,16 @@ impl AuthorizationError {
409
409
// Only display the _TOKEN environment variable suggestion if the `cargo:token` credential
410
410
// provider is available for the source. Otherwise setting the environment variable will
411
411
// 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" ) ) ;
415
416
Ok ( AuthorizationError {
416
417
sid,
417
418
default_registry : gctx. default_registry ( ) ?,
418
419
login_url,
419
420
reason,
420
- display_token_env_help ,
421
+ supports_cargo_token_credential_provider ,
421
422
} )
422
423
}
423
424
}
@@ -432,20 +433,30 @@ impl fmt::Display for AuthorizationError {
432
433
""
433
434
} ;
434
435
write ! ( f, "{}, please run `cargo login{args}`" , self . reason) ?;
435
- if self . display_token_env_help {
436
+ if self . supports_cargo_token_credential_provider {
436
437
write ! ( f, "\n or use environment variable CARGO_REGISTRY_TOKEN" ) ?;
437
438
}
438
439
Ok ( ( ) )
439
440
} else if let Some ( name) = self . sid . alt_registry_key ( ) {
440
- let key = ConfigKey :: from_str ( & format ! ( "registries.{name}.token" ) ) ;
441
441
write ! (
442
442
f,
443
- "{} for `{}`, please run `cargo login --registry {name}` " ,
443
+ "{} for `{}`" ,
444
444
self . reason,
445
- self . sid. display_registry_name( ) ,
445
+ self . sid. display_registry_name( )
446
446
) ?;
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
+ ) ?;
449
460
}
450
461
Ok ( ( ) )
451
462
} else if self . reason == AuthorizationErrorReason :: TokenMissing {
0 commit comments