Better exception handling

This commit is contained in:
Ivan Kravets
2016-08-26 12:30:37 +03:00
parent f9e8ea66ea
commit 6e26ce8162
4 changed files with 20 additions and 8 deletions

View File

@ -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:

View File

@ -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}'"

View File

@ -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(

View File

@ -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),