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