@@ -8,6 +8,7 @@ use std::{cmp, env};
8
8
9
9
use crates_io:: { NewCrate , NewCrateDependency , Registry } ;
10
10
use curl:: easy:: { Easy , InfoType , SslOpt } ;
11
+ use failure:: { bail, format_err} ;
11
12
use log:: { log, Level } ;
12
13
use url:: percent_encoding:: { percent_encode, QUERY_ENCODE_SET } ;
13
14
@@ -16,7 +17,7 @@ use crate::core::manifest::ManifestMetadata;
16
17
use crate :: core:: source:: Source ;
17
18
use crate :: core:: { Package , SourceId , Workspace } ;
18
19
use crate :: ops;
19
- use crate :: sources:: { RegistrySource , SourceConfigMap } ;
20
+ use crate :: sources:: { RegistrySource , SourceConfigMap , CRATES_IO_REGISTRY } ;
20
21
use crate :: util:: config:: { self , Config } ;
21
22
use crate :: util:: errors:: { CargoResult , CargoResultExt } ;
22
23
use crate :: util:: important_paths:: find_root_manifest_for_wd;
@@ -48,14 +49,16 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
48
49
let pkg = ws. current ( ) ?;
49
50
50
51
if let Some ( ref allowed_registries) = * pkg. publish ( ) {
51
- if !match opts. registry {
52
- Some ( ref registry) => allowed_registries. contains ( registry) ,
53
- None => false ,
54
- } {
55
- failure:: bail!(
56
- "some crates cannot be published.\n \
57
- `{}` is marked as unpublishable",
58
- pkg. name( )
52
+ let reg_name = opts
53
+ . registry
54
+ . clone ( )
55
+ . unwrap_or_else ( || CRATES_IO_REGISTRY . to_string ( ) ) ;
56
+ if !allowed_registries. contains ( & reg_name) {
57
+ bail ! (
58
+ "`{}` cannot be published.\n \
59
+ The registry `{}` is not listed in the `publish` value in Cargo.toml.",
60
+ pkg. name( ) ,
61
+ reg_name
59
62
) ;
60
63
}
61
64
}
@@ -112,7 +115,7 @@ fn verify_dependencies(
112
115
for dep in pkg. dependencies ( ) . iter ( ) {
113
116
if dep. source_id ( ) . is_path ( ) {
114
117
if !dep. specified_req ( ) {
115
- failure :: bail!(
118
+ bail ! (
116
119
"all path dependencies must have a version specified \
117
120
when publishing.\n dependency `{}` does not specify \
118
121
a version",
@@ -131,7 +134,7 @@ fn verify_dependencies(
131
134
. map ( |u| u. host_str ( ) == Some ( "crates.io" ) )
132
135
. unwrap_or ( false ) ;
133
136
if registry_src. is_default_registry ( ) || is_crates_io {
134
- failure :: bail!( "crates cannot be published to crates.io with dependencies sourced from other\n \
137
+ bail ! ( "crates cannot be published to crates.io with dependencies sourced from other\n \
135
138
registries either publish `{}` on crates.io or pull it into this repository\n \
136
139
and specify it with a path and version\n \
137
140
(crate `{}` is pulled from {})",
@@ -140,7 +143,7 @@ fn verify_dependencies(
140
143
dep. source_id( ) ) ;
141
144
}
142
145
} else {
143
- failure :: bail!(
146
+ bail ! (
144
147
"crates cannot be published with dependencies sourced from \
145
148
a repository\n either publish `{}` as its own crate and \
146
149
specify a version as a dependency or pull it into this \
@@ -221,7 +224,7 @@ fn transmit(
221
224
} ;
222
225
if let Some ( ref file) = * license_file {
223
226
if fs:: metadata ( & pkg. root ( ) . join ( file) ) . is_err ( ) {
224
- failure :: bail!( "the license file `{}` does not exist" , file)
227
+ bail ! ( "the license file `{}` does not exist" , file)
225
228
}
226
229
}
227
230
@@ -357,7 +360,7 @@ pub fn registry(
357
360
cfg. unwrap ( )
358
361
} ;
359
362
cfg. and_then ( |cfg| cfg. api )
360
- . ok_or_else ( || failure :: format_err!( "{} does not support API commands" , sid) ) ?
363
+ . ok_or_else ( || format_err ! ( "{} does not support API commands" , sid) ) ?
361
364
} ;
362
365
let handle = http_handle ( config) ?;
363
366
Ok ( ( Registry :: new_handle ( api_host, token, handle) , sid) )
@@ -372,13 +375,13 @@ pub fn http_handle(config: &Config) -> CargoResult<Easy> {
372
375
373
376
pub fn http_handle_and_timeout ( config : & Config ) -> CargoResult < ( Easy , HttpTimeout ) > {
374
377
if config. frozen ( ) {
375
- failure :: bail!(
378
+ bail ! (
376
379
"attempting to make an HTTP request, but --frozen was \
377
380
specified"
378
381
)
379
382
}
380
383
if !config. network_allowed ( ) {
381
- failure :: bail!( "can't make HTTP request in the offline mode" )
384
+ bail ! ( "can't make HTTP request in the offline mode" )
382
385
}
383
386
384
387
// The timeout option for libcurl by default times out the entire transfer,
@@ -605,9 +608,9 @@ pub fn modify_owners(config: &Config, opts: &OwnersOptions) -> CargoResult<()> {
605
608
606
609
if let Some ( ref v) = opts. to_add {
607
610
let v = v. iter ( ) . map ( |s| & s[ ..] ) . collect :: < Vec < _ > > ( ) ;
608
- let msg = registry. add_owners ( & name , & v ) . map_err ( |e| {
609
- failure :: format_err! ( "failed to invite owners to crate {}: {}" , name, e )
610
- } ) ?;
611
+ let msg = registry
612
+ . add_owners ( & name, & v )
613
+ . map_err ( |e| format_err ! ( "failed to invite owners to crate {}: {}" , name , e ) ) ?;
611
614
612
615
config. shell ( ) . status ( "Owner" , msg) ?;
613
616
}
@@ -658,7 +661,7 @@ pub fn yank(
658
661
} ;
659
662
let version = match version {
660
663
Some ( v) => v,
661
- None => failure :: bail!( "a version must be specified to yank" ) ,
664
+ None => bail ! ( "a version must be specified to yank" ) ,
662
665
} ;
663
666
664
667
let ( mut registry, _) = registry ( config, token, index, reg, true ) ?;
0 commit comments