File tree Expand file tree Collapse file tree 2 files changed +27
-9
lines changed Expand file tree Collapse file tree 2 files changed +27
-9
lines changed Original file line number Diff line number Diff line change @@ -276,7 +276,7 @@ impl RustWasm {
276
276
ExportKey :: Name ( name) => format ! ( "\" {name}\" " ) ,
277
277
} ;
278
278
if self . opts . exports . is_empty ( ) {
279
- bail ! ( "no `exports` map provided in configuration - provide an `exports` map a key `{key}`" )
279
+ bail ! ( MissingExportsMap { key } ) ;
280
280
}
281
281
bail ! ( "expected `exports` map to contain key `{key}`" )
282
282
}
@@ -869,3 +869,20 @@ impl fmt::Display for RustFlagsRepr {
869
869
}
870
870
}
871
871
}
872
+
873
+ #[ derive( Debug ) ]
874
+ pub struct MissingExportsMap {
875
+ key : String ,
876
+ }
877
+
878
+ impl fmt:: Display for MissingExportsMap {
879
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
880
+ write ! (
881
+ f,
882
+ "no `exports` map provided in configuration - provide an `exports` map a key `{key}`" ,
883
+ key = self . key,
884
+ )
885
+ }
886
+ }
887
+
888
+ impl std:: error:: Error for MissingExportsMap { }
Original file line number Diff line number Diff line change @@ -157,16 +157,17 @@ fn gen_world(
157
157
let mut resolve = Resolve :: default ( ) ;
158
158
let ( pkg, _files) = resolve. push_path ( & opts. wit ) ?;
159
159
let world = resolve. select_world ( pkg, opts. world . as_deref ( ) ) ?;
160
- if let Err ( e) = generator. generate ( & resolve, world, files) {
161
- if e. to_string ( ) . starts_with ( "no `exports` map provided" ) {
162
- bail ! (
163
- "{e:?}\n \n \
164
- help: Specify export implementations using the `--exports` option.\n \
165
- For example: `--exports world=MyWorld,ns:pkg/iface=MyIface`\n \
166
- Alternatively, specify `--stubs` to generate stub implementations."
160
+ if let Err ( mut e) = generator. generate ( & resolve, world, files) {
161
+ #[ cfg( feature = "rust" ) ]
162
+ if e. is :: < wit_bindgen_rust:: MissingExportsMap > ( ) {
163
+ e = e. context (
164
+ "no `--exports` option was found but one was required, \
165
+ this can be passed as `--exports world=MyWorld,ns:pkg/iface=MyIface` \
166
+ for example\n \
167
+ Alternatively, specify `--stubs` to generate stub implementations.",
167
168
) ;
168
169
}
169
- bail ! ( "{e:?}" ) ;
170
+ return Err ( e ) ;
170
171
}
171
172
172
173
Ok ( ( ) )
You can’t perform that action at this time.
0 commit comments