File tree Expand file tree Collapse file tree 2 files changed +29
-8
lines changed Expand file tree Collapse file tree 2 files changed +29
-8
lines changed Original file line number Diff line number Diff line change @@ -541,21 +541,19 @@ class WebPlugin extends PluginPlatform {
541541 });
542542
543543 factory WebPlugin .fromYaml (String name, YamlMap yaml) {
544- assert (validate (yaml));
544+ if (yaml['pluginClass' ] is ! String ) {
545+ throwToolExit ('The plugin `$name ` is missing the required field `pluginClass` in pubspec.yaml' );
546+ }
547+ if (yaml['fileName' ] is ! String ) {
548+ throwToolExit ('The plugin `$name ` is missing the required field `fileName` in pubspec.yaml' );
549+ }
545550 return WebPlugin (
546551 name: name,
547552 pluginClass: yaml['pluginClass' ] as String ,
548553 fileName: yaml['fileName' ] as String ,
549554 );
550555 }
551556
552- static bool validate (YamlMap yaml) {
553- if (yaml == null ) {
554- return false ;
555- }
556- return yaml['pluginClass' ] is String && yaml['fileName' ] is String ;
557- }
558-
559557 static const String kConfigKey = 'web' ;
560558
561559 /// The name of the plugin.
Original file line number Diff line number Diff line change @@ -290,6 +290,29 @@ void main() {
290290 ]);
291291 });
292292
293+ testWithoutContext ('Web plugin tool exits if fileName field missing' , () {
294+ final FileSystem fileSystem = MemoryFileSystem .test ();
295+ const String pluginYamlRaw =
296+ 'platforms:\n '
297+ ' web:\n '
298+ ' pluginClass: WebSamplePlugin\n ' ;
299+
300+ final YamlMap pluginYaml = loadYaml (pluginYamlRaw) as YamlMap ;
301+ expect (
302+ () => Plugin .fromYaml (
303+ _kTestPluginName,
304+ _kTestPluginPath,
305+ pluginYaml,
306+ null ,
307+ const < String > [],
308+ fileSystem: fileSystem,
309+ ),
310+ throwsToolExit (
311+ message: 'The plugin `$_kTestPluginName ` is missing the required field `fileName` in pubspec.yaml' ,
312+ ),
313+ );
314+ });
315+
293316 testWithoutContext ('Windows assumes win32 when no variants are given' , () {
294317 final FileSystem fileSystem = MemoryFileSystem .test ();
295318 const String pluginYamlRaw =
You can’t perform that action at this time.
0 commit comments