mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-30 10:07: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()
|
storage_dir = util.get_projectlibdeps_dir()
|
||||||
|
|
||||||
if not storage_dir and not util.is_platformio_project():
|
if not storage_dir and not util.is_platformio_project():
|
||||||
raise exception.PlatformioException(
|
raise exception.NotGlobalLibDir(util.get_project_dir(),
|
||||||
"The `%s` is not a PlatformIO project.\nTo manage libraries "
|
join(util.get_home_dir(), "lib"),
|
||||||
"in the global storage `%s`, please use "
|
ctx.invoked_subcommand)
|
||||||
"`platformio lib --global %s` instead." %
|
|
||||||
(util.get_project_dir(), join(util.get_home_dir(), "lib"),
|
|
||||||
ctx.invoked_subcommand))
|
|
||||||
|
|
||||||
ctx.obj = LibraryManager(storage_dir)
|
ctx.obj = LibraryManager(storage_dir)
|
||||||
if "--json-output" not in ctx.args:
|
if "--json-output" not in ctx.args:
|
||||||
|
@ -156,6 +156,16 @@ class LibNotFound(PlatformioException):
|
|||||||
MESSAGE = "Library `{0}` has not been found in the registry"
|
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):
|
class InvalidLibConfURL(PlatformioException):
|
||||||
|
|
||||||
MESSAGE = "Invalid library config URL '{0}'"
|
MESSAGE = "Invalid library config URL '{0}'"
|
||||||
|
@ -238,7 +238,10 @@ class LibraryManager(BasePkgManager):
|
|||||||
break
|
break
|
||||||
|
|
||||||
if not lib_info:
|
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:
|
if not silent:
|
||||||
click.echo("Found: %s" % click.style(
|
click.echo("Found: %s" % click.style(
|
||||||
"http://platformio.org/lib/show/{id}/{name}".format(
|
"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):
|
def on_exception(e):
|
||||||
if isinstance(e, exception.AbortedByUser):
|
if any([isinstance(e, cls)
|
||||||
|
for cls in (IOError, exception.AbortedByUser,
|
||||||
|
exception.NotGlobalLibDir)]):
|
||||||
return
|
return
|
||||||
is_crash = any([
|
is_crash = any([
|
||||||
not isinstance(e, exception.PlatformioException),
|
not isinstance(e, exception.PlatformioException),
|
||||||
|
Reference in New Issue
Block a user