mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-30 01:57:13 +02:00
Better exceptions handling
This commit is contained in:
@ -103,6 +103,19 @@ def main():
|
|||||||
error_str += str(e)
|
error_str += str(e)
|
||||||
else:
|
else:
|
||||||
error_str += format_exc()
|
error_str += format_exc()
|
||||||
|
|
||||||
|
error_str += """
|
||||||
|
============================================================
|
||||||
|
|
||||||
|
An unexpected error occurred. Further steps:
|
||||||
|
|
||||||
|
* Verify that you have the latest version of PlatformIO using
|
||||||
|
`platformio upgrade` command
|
||||||
|
* Report this problem to the developers
|
||||||
|
https://github.com/platformio/platformio/issues
|
||||||
|
|
||||||
|
============================================================
|
||||||
|
"""
|
||||||
click.secho(error_str, fg="red", err=True)
|
click.secho(error_str, fg="red", err=True)
|
||||||
return 1
|
return 1
|
||||||
return 0
|
return 0
|
||||||
|
@ -135,7 +135,7 @@ def lib_install(ctx, libid, version):
|
|||||||
except AssertionError:
|
except AssertionError:
|
||||||
raise exception.LibInstallDependencyError(str(item))
|
raise exception.LibInstallDependencyError(str(item))
|
||||||
|
|
||||||
except exception.LibAlreadyInstalledError:
|
except exception.LibAlreadyInstalled:
|
||||||
click.secho("Already installed", fg="yellow")
|
click.secho("Already installed", fg="yellow")
|
||||||
|
|
||||||
|
|
||||||
|
@ -56,9 +56,9 @@ def cli():
|
|||||||
click.echo("Release notes: ", nl=False)
|
click.echo("Release notes: ", nl=False)
|
||||||
click.secho("http://docs.platformio.org/en/latest/history.html",
|
click.secho("http://docs.platformio.org/en/latest/history.html",
|
||||||
fg="cyan")
|
fg="cyan")
|
||||||
except (OSError, AssertionError) as e:
|
except Exception as e: # pylint: disable=W0703
|
||||||
if not r:
|
if not r:
|
||||||
raise exception.PlatformioUpgradeError(
|
raise exception.UpgradeError(
|
||||||
"\n".join([str(cmd), str(e)]))
|
"\n".join([str(cmd), str(e)]))
|
||||||
if ("Permission denied" in r['err'] and
|
if ("Permission denied" in r['err'] and
|
||||||
"windows" not in util.get_systype()):
|
"windows" not in util.get_systype()):
|
||||||
@ -74,7 +74,7 @@ WARNING! Don't use `sudo` for the rest PlatformIO commands.
|
|||||||
""", fg="yellow", err=True)
|
""", fg="yellow", err=True)
|
||||||
raise exception.ReturnErrorCode()
|
raise exception.ReturnErrorCode()
|
||||||
else:
|
else:
|
||||||
raise exception.PlatformioUpgradeError(
|
raise exception.UpgradeError(
|
||||||
"\n".join([str(cmd), r['out'], r['err']]))
|
"\n".join([str(cmd), r['out'], r['err']]))
|
||||||
|
|
||||||
|
|
||||||
|
@ -149,11 +149,11 @@ class APIRequestError(PlatformioException):
|
|||||||
MESSAGE = "[API] %s"
|
MESSAGE = "[API] %s"
|
||||||
|
|
||||||
|
|
||||||
class LibAlreadyInstalledError(PlatformioException):
|
class LibAlreadyInstalled(PlatformioException):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class LibNotInstalledError(PlatformioException):
|
class LibNotInstalled(PlatformioException):
|
||||||
|
|
||||||
MESSAGE = "Library #%d has not been installed yet"
|
MESSAGE = "Library #%d has not been installed yet"
|
||||||
|
|
||||||
@ -183,11 +183,6 @@ class InvalidSettingValue(PlatformioException):
|
|||||||
MESSAGE = "Invalid value '%s' for the setting '%s'"
|
MESSAGE = "Invalid value '%s' for the setting '%s'"
|
||||||
|
|
||||||
|
|
||||||
class UpgraderFailed(PlatformioException):
|
|
||||||
|
|
||||||
MESSAGE = "An error occurred while upgrading PlatformIO"
|
|
||||||
|
|
||||||
|
|
||||||
class CIBuildEnvsEmpty(PlatformioException):
|
class CIBuildEnvsEmpty(PlatformioException):
|
||||||
|
|
||||||
MESSAGE = "Can't find PlatformIO build environments.\n"\
|
MESSAGE = "Can't find PlatformIO build environments.\n"\
|
||||||
@ -195,20 +190,20 @@ class CIBuildEnvsEmpty(PlatformioException):
|
|||||||
"predefined environments using `--project-conf` option"
|
"predefined environments using `--project-conf` option"
|
||||||
|
|
||||||
|
|
||||||
class SConsNotInstalled(PlatformioException):
|
class SConsNotInstalledError(PlatformioException):
|
||||||
|
|
||||||
MESSAGE = "The PlatformIO and `scons` aren't installed properly. "\
|
MESSAGE = "The PlatformIO and `scons` aren't installed properly. "\
|
||||||
"More details in FAQ/Troubleshooting section: "\
|
"More details in FAQ/Troubleshooting section: "\
|
||||||
"http://docs.platformio.org/en/latest/faq.html"
|
"http://docs.platformio.org/en/latest/faq.html"
|
||||||
|
|
||||||
|
|
||||||
class PlatformioUpgradeError(PlatformioException):
|
class UpgradeError(PlatformioException):
|
||||||
|
|
||||||
MESSAGE = "%s \n\n"\
|
MESSAGE = """%s
|
||||||
"1. Please report this issue here: "\
|
|
||||||
"https://github.com/platformio/platformio/issues \n"\
|
* Try different installation/upgrading steps:
|
||||||
"2. Try different installation/upgrading steps: "\
|
http://docs.platformio.org/en/latest/installation.html
|
||||||
"http://docs.platformio.org/en/latest/installation.html"
|
"""
|
||||||
|
|
||||||
|
|
||||||
class CygwinEnvDetected(PlatformioException):
|
class CygwinEnvDetected(PlatformioException):
|
||||||
|
@ -21,7 +21,7 @@ from tempfile import gettempdir
|
|||||||
|
|
||||||
from platformio import telemetry, util
|
from platformio import telemetry, util
|
||||||
from platformio.downloader import FileDownloader
|
from platformio.downloader import FileDownloader
|
||||||
from platformio.exception import LibAlreadyInstalledError, LibNotInstalledError
|
from platformio.exception import LibAlreadyInstalled, LibNotInstalled
|
||||||
from platformio.unpacker import FileUnpacker
|
from platformio.unpacker import FileUnpacker
|
||||||
|
|
||||||
|
|
||||||
@ -73,17 +73,17 @@ class LibraryManager(object):
|
|||||||
for item in self.get_installed().values():
|
for item in self.get_installed().values():
|
||||||
if "id" in item and item['id'] == id_:
|
if "id" in item and item['id'] == id_:
|
||||||
return item
|
return item
|
||||||
raise LibNotInstalledError(id_)
|
raise LibNotInstalled(id_)
|
||||||
|
|
||||||
def is_installed(self, id_):
|
def is_installed(self, id_):
|
||||||
try:
|
try:
|
||||||
return int(self.get_info(id_)['id']) == id_
|
return int(self.get_info(id_)['id']) == id_
|
||||||
except LibNotInstalledError:
|
except LibNotInstalled:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def install(self, id_, version=None):
|
def install(self, id_, version=None):
|
||||||
if self.is_installed(id_):
|
if self.is_installed(id_):
|
||||||
raise LibAlreadyInstalledError()
|
raise LibAlreadyInstalled()
|
||||||
|
|
||||||
dlinfo = util.get_api_result(
|
dlinfo = util.get_api_result(
|
||||||
"/lib/download/" + str(id_),
|
"/lib/download/" + str(id_),
|
||||||
@ -120,4 +120,4 @@ class LibraryManager(object):
|
|||||||
label="#%d %s" % (id_, item['name'])
|
label="#%d %s" % (id_, item['name'])
|
||||||
)
|
)
|
||||||
return True
|
return True
|
||||||
raise LibNotInstalledError(id_)
|
raise LibNotInstalled(id_)
|
||||||
|
@ -145,11 +145,6 @@ def after_upgrade(ctx):
|
|||||||
click.style("give", fg="cyan"),
|
click.style("give", fg="cyan"),
|
||||||
click.style("https://github.com/platformio/platformio", fg="cyan")
|
click.style("https://github.com/platformio/platformio", fg="cyan")
|
||||||
))
|
))
|
||||||
click.echo("- %s for the new features/issues on Bountysource > %s" % (
|
|
||||||
click.style("vote", fg="cyan"),
|
|
||||||
click.style("https://www.bountysource.com/teams/platformio/issues",
|
|
||||||
fg="cyan")
|
|
||||||
))
|
|
||||||
click.echo("*" * terminal_width)
|
click.echo("*" * terminal_width)
|
||||||
click.echo("")
|
click.echo("")
|
||||||
|
|
||||||
@ -171,7 +166,7 @@ def after_upgrade(ctx):
|
|||||||
telemetry.on_event(category="Auto", action="Upgrade",
|
telemetry.on_event(category="Auto", action="Upgrade",
|
||||||
label="%s > %s" % (last_version, __version__))
|
label="%s > %s" % (last_version, __version__))
|
||||||
else:
|
else:
|
||||||
raise exception.UpgraderFailed()
|
raise exception.UpgradeError("Auto upgrading...")
|
||||||
click.echo("")
|
click.echo("")
|
||||||
|
|
||||||
|
|
||||||
|
@ -395,7 +395,7 @@ class BasePlatform(object):
|
|||||||
stderr=util.AsyncPipe(self.on_run_err)
|
stderr=util.AsyncPipe(self.on_run_err)
|
||||||
)
|
)
|
||||||
except (OSError, AssertionError):
|
except (OSError, AssertionError):
|
||||||
raise exception.SConsNotInstalled()
|
raise exception.SConsNotInstalledError()
|
||||||
|
|
||||||
assert "returncode" in result
|
assert "returncode" in result
|
||||||
# if self._found_error:
|
# if self._found_error:
|
||||||
|
@ -291,7 +291,10 @@ def on_exception(e):
|
|||||||
return
|
return
|
||||||
mp = MeasurementProtocol()
|
mp = MeasurementProtocol()
|
||||||
mp['exd'] = "%s: %s" % (type(e).__name__, e)
|
mp['exd'] = "%s: %s" % (type(e).__name__, e)
|
||||||
mp['exf'] = int(not isinstance(e, exception.PlatformioException))
|
mp['exf'] = int(any([
|
||||||
|
not isinstance(e, exception.PlatformioException),
|
||||||
|
"Error" in e.__class__.__name__
|
||||||
|
]))
|
||||||
mp.send("exception")
|
mp.send("exception")
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user