manifest: ManifestImportFailed: relax argument specification

Continue to accept all arguments previously accepted, but widen the
allowed argument types as follows:

- Allow passing a None argument as the project to signal the manifest
  repository is where the import is happening. This will be useful for
  allowing us to continue using this exception type without mandating
  use of the ManifestProject class, which we'd like to get rid of
  eventually.

- Generalize the 'filename' argument to allow specifying arbitrary
  import data which could not be imported. This will be useful for
  specifying failures that happen when importing a map by giving the
  entire map that failed to import, instead of just a file name.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
This commit is contained in:
Martí Bolívar 2022-03-18 13:54:06 -07:00 committed by Marti Bolivar
parent d3e05e71bd
commit 2327610945
1 changed files with 13 additions and 7 deletions

View File

@ -547,18 +547,24 @@ class ManifestImportFailed(Exception):
Attributes:
- ``project``: the Project instance with the missing manifest data
- ``filename``: the missing file, as a str
- ``project``: the Project instance with the missing manifest data;
None if it's from the manifest via "manifest: self: import:"
- ``imp``: the parsed YAML data whose import was requested
'''
def __init__(self, project: 'Project', filename: PathType):
super().__init__(project, filename)
def __init__(self, project: Optional['Project'], imp: Any):
super().__init__()
self.project = project
self.filename = os.fspath(filename)
self.imp = imp
def __str__(self):
return (f'ManifestImportFailed: project {self.project} '
f'file {self.filename}')
if self.project is not None:
return (f'ManifestImportFailed: project {self.project} '
f'value {self.imp}')
else:
return (f'ManifestImportFailed: manifest repository '
f'value {self.imp}')
class ManifestVersionError(Exception):
'''The manifest required a version of west more recent than the