Show error name when raising UserSideException

This commit is contained in:
Ivan Kravets
2023-06-21 13:47:45 +03:00
parent 326ebcf593
commit e25b170b34
4 changed files with 27 additions and 18 deletions

View File

@ -107,7 +107,7 @@ def main(argv=None):
except Exception as exc: # pylint: disable=broad-except
if not isinstance(exc, exception.ReturnErrorCode):
maintenance.on_platformio_exception(exc)
error_str = "Error: "
error_str = f"{exc.__class__.__name__}: "
if isinstance(exc, exception.PlatformioException):
error_str += str(exc)
else:

View File

@ -24,7 +24,7 @@ import semantic_version
from platformio import fs
from platformio.compat import get_object_members, hashlib_encode_data, string_types
from platformio.package.manifest.parser import ManifestFileType
from platformio.package.version import cast_version_to_semver
from platformio.package.version import SemanticVersionError, cast_version_to_semver
from platformio.util import items_in_list
@ -175,7 +175,7 @@ class PackageSpec: # pylint: disable=too-many-instance-attributes
if requirements:
try:
self.requirements = requirements
except ValueError as exc:
except SemanticVersionError as exc:
if not self.name or self.uri or self.raw:
raise exc
self.raw = "%s=%s" % (self.name, requirements)
@ -224,11 +224,14 @@ class PackageSpec: # pylint: disable=too-many-instance-attributes
if not value:
self._requirements = None
return
self._requirements = (
value
if isinstance(value, semantic_version.SimpleSpec)
else semantic_version.SimpleSpec(str(value))
)
try:
self._requirements = (
value
if isinstance(value, semantic_version.SimpleSpec)
else semantic_version.SimpleSpec(str(value))
)
except ValueError as exc:
raise SemanticVersionError(exc) from exc
def humanize(self):
result = ""

View File

@ -16,6 +16,12 @@ import re
import semantic_version
from platformio.exception import UserSideException
class SemanticVersionError(UserSideException):
pass
def cast_version_to_semver(value, force=True, raise_exception=False):
assert value
@ -29,7 +35,7 @@ def cast_version_to_semver(value, force=True, raise_exception=False):
except ValueError:
pass
if raise_exception:
raise ValueError("Invalid SemVer version %s" % value)
raise SemanticVersionError("Invalid SemVer version %s" % value)
# parse commit hash
if re.match(r"^[\da-f]+$", value, flags=re.I):
return semantic_version.Version("0.0.0+sha." + value)

View File

@ -12,14 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from platformio.exception import PlatformioException, UserSideException
from platformio.exception import UserSideException
class ProjectError(PlatformioException):
class ProjectError(UserSideException):
pass
class NotPlatformIOProjectError(ProjectError, UserSideException):
class NotPlatformIOProjectError(ProjectError):
MESSAGE = (
"Not a PlatformIO project. `platformio.ini` file has not been "
"found in current working directory ({0}). To initialize new project "
@ -27,28 +27,28 @@ class NotPlatformIOProjectError(ProjectError, UserSideException):
)
class InvalidProjectConfError(ProjectError, UserSideException):
class InvalidProjectConfError(ProjectError):
MESSAGE = "Invalid '{0}' (project configuration file): '{1}'"
class UndefinedEnvPlatformError(ProjectError, UserSideException):
class UndefinedEnvPlatformError(ProjectError):
MESSAGE = "Please specify platform for '{0}' environment"
class ProjectEnvsNotAvailableError(ProjectError, UserSideException):
class ProjectEnvsNotAvailableError(ProjectError):
MESSAGE = "Please setup environments in `platformio.ini` file"
class UnknownEnvNamesError(ProjectError, UserSideException):
class UnknownEnvNamesError(ProjectError):
MESSAGE = "Unknown environment names '{0}'. Valid names are '{1}'"
class InvalidEnvNameError(ProjectError, UserSideException):
class InvalidEnvNameError(ProjectError):
MESSAGE = (
"Invalid environment name '{0}'. The name can contain "
"alphanumeric, underscore, and hyphen characters (a-z, 0-9, -, _)"
)
class ProjectOptionValueError(ProjectError, UserSideException):
class ProjectOptionValueError(ProjectError):
MESSAGE = "{0} for option `{1}` in section [{2}]"