mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-29 17:47:14 +02:00
Better exception handling
This commit is contained in:
@ -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:
|
||||
|
@ -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}'"
|
||||
|
@ -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(
|
||||
|
@ -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),
|
||||
|
Reference in New Issue
Block a user