pw_doctor: Check that pw plugins all loaded

Change-Id: I147d1eb552be601421ed358ae5a4b9785a4b1320
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/24220
Pigweed-Auto-Submit: Rob Mohr <mohrr@google.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
Reviewed-by: Armando Montanez <amontanez@google.com>
diff --git a/pw_cli/py/pw_cli/plugins.py b/pw_cli/py/pw_cli/plugins.py
index db77fcf..687dd01 100644
--- a/pw_cli/py/pw_cli/plugins.py
+++ b/pw_cli/py/pw_cli/plugins.py
@@ -116,6 +116,10 @@
     raise Error(f'The plugin "{name}" has not been registered')
 
 
+def errors() -> Dict[str, List[Error]]:
+    return _errors
+
+
 def run(name: str, args: List[str]) -> int:
     """Runs a plugin by name. Raises Error if the plugin is not registered."""
     return _get(name).run(args)
@@ -237,7 +241,8 @@
                     try:
                         name, module, function = line.split()
                         _register(name, module, function, path)
-                    except ValueError:
+                    except ValueError as err:
+                        _errors[line.strip()].append(Error(err))
                         _LOG.error(
                             '%s:%d: Failed to parse plugin entry "%s": '
                             'Expected 3 items (name, module, function), got %d',
diff --git a/pw_doctor/py/pw_doctor/doctor.py b/pw_doctor/py/pw_doctor/doctor.py
index 58cd1d8..e1ba7ad 100755
--- a/pw_doctor/py/pw_doctor/doctor.py
+++ b/pw_doctor/py/pw_doctor/doctor.py
@@ -26,6 +26,8 @@
 import tempfile
 from typing import Callable, Iterable, List, Set
 
+import pw_cli.plugins
+
 
 def call_stdout(*args, **kwargs):
     kwargs.update(stdout=subprocess.PIPE)
@@ -127,6 +129,12 @@
 
 
 @register_into(CHECKS)
+def pw_plugins(ctx: DoctorContext):
+    if pw_cli.plugins.errors():
+        ctx.error('Not all pw plugins loaded successfully')
+
+
+@register_into(CHECKS)
 def env_os(ctx: DoctorContext):
     """Check that the environment matches this machine."""
     if '_PW_ACTUAL_ENVIRONMENT_ROOT' not in os.environ: