From 6e26ce816263c56b91d3386a8d7aedf5d055d164 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Fri, 26 Aug 2016 12:30:37 +0300 Subject: [PATCH] Better exception handling --- platformio/commands/lib.py | 9 +++------ platformio/exception.py | 10 ++++++++++ platformio/managers/lib.py | 5 ++++- platformio/telemetry.py | 4 +++- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/platformio/commands/lib.py b/platformio/commands/lib.py index 348c3e05..ba179b63 100644 --- a/platformio/commands/lib.py +++ b/platformio/commands/lib.py @@ -55,12 +55,9 @@ def cli(ctx, **options): storage_dir = util.get_projectlibdeps_dir() if not storage_dir and not util.is_platformio_project(): - raise exception.PlatformioException( - "The `%s` is not a PlatformIO project.\nTo manage libraries " - "in the global storage `%s`, please use " - "`platformio lib --global %s` instead." % - (util.get_project_dir(), join(util.get_home_dir(), "lib"), - ctx.invoked_subcommand)) + raise exception.NotGlobalLibDir(util.get_project_dir(), + join(util.get_home_dir(), "lib"), + ctx.invoked_subcommand) ctx.obj = LibraryManager(storage_dir) if "--json-output" not in ctx.args: diff --git a/platformio/exception.py b/platformio/exception.py index 6d3a7641..4baf827f 100644 --- a/platformio/exception.py +++ b/platformio/exception.py @@ -156,6 +156,16 @@ class LibNotFound(PlatformioException): MESSAGE = "Library `{0}` has not been found in the registry" +class NotGlobalLibDir(PlatformioException): + + MESSAGE = "The `{0}` is not a PlatformIO project.\n\n"\ + "To manage libraries "\ + "in global storage `{1}`,\n"\ + "please use `platformio lib --global {2}` or specify custom "\ + "storage `platformio lib --storage-dir /path/to/storage/ {2}`."\ + "\nCheck `platformio lib --help` for details." + + class InvalidLibConfURL(PlatformioException): MESSAGE = "Invalid library config URL '{0}'" diff --git a/platformio/managers/lib.py b/platformio/managers/lib.py index a8a5af23..379b6d22 100644 --- a/platformio/managers/lib.py +++ b/platformio/managers/lib.py @@ -238,7 +238,10 @@ class LibraryManager(BasePkgManager): break if not lib_info: - raise exception.LibNotFound(str(filters)) + if filters.keys() == ["name"]: + raise exception.LibNotFound(filters['name']) + else: + raise exception.LibNotFound(str(filters)) if not silent: click.echo("Found: %s" % click.style( "http://platformio.org/lib/show/{id}/{name}".format( diff --git a/platformio/telemetry.py b/platformio/telemetry.py index 47150149..08a8302d 100644 --- a/platformio/telemetry.py +++ b/platformio/telemetry.py @@ -268,7 +268,9 @@ def on_event(category, action, label=None, value=None, screen_name=None): def on_exception(e): - if isinstance(e, exception.AbortedByUser): + if any([isinstance(e, cls) + for cls in (IOError, exception.AbortedByUser, + exception.NotGlobalLibDir)]): return is_crash = any([ not isinstance(e, exception.PlatformioException),