File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -33,7 +33,14 @@ fn main() {
33
33
return ;
34
34
}
35
35
36
- let workspace_root = workspace_root ( ) ;
36
+ let workspace_root = match workspace_root ( ) {
37
+ Ok ( root) => root,
38
+ Err ( _) => {
39
+ println ! ( "Error: could not find workspace root" ) ;
40
+ println ! ( "`cargo src` run outside a Cargo project" ) ;
41
+ std:: process:: exit ( 1 ) ;
42
+ }
43
+ } ;
37
44
38
45
let build_args = BuildArgs {
39
46
program : env:: var ( "CARGO" ) . expect ( "Missing $CARGO var" ) ,
@@ -55,11 +62,11 @@ fn print_help() {
55
62
println ! ( "\n Other options follow `cargo check`, see `cargo check --help` for more." ) ;
56
63
}
57
64
58
- fn workspace_root ( ) -> String {
65
+ fn workspace_root ( ) -> Result < String , serde_json :: Error > {
59
66
let output = Command :: new ( "cargo" ) . args ( & [ "metadata" , "--format-version" , "1" ] ) . output ( ) ;
60
67
let stdout = String :: from_utf8 ( output. expect ( "error executing `cargo metadata`" ) . stdout ) . expect ( "unexpected output" ) ;
61
- let json: Metadata = serde_json:: from_str ( & stdout) . expect ( "error parsing json from `cargo metadata`" ) ;
62
- json. workspace_root
68
+ let json: Metadata = serde_json:: from_str ( & stdout) ? ;
69
+ Ok ( json. workspace_root )
63
70
}
64
71
65
72
#[ derive( Deserialize ) ]
You can’t perform that action at this time.
0 commit comments