Use ProjectNotFoundError
This error is used in some places, but not all. Correct that to improve config error structured data. Change-Id: Ice4fbee679ff8e7ab05042452bbd4f45ca8f1122
This commit is contained in:
parent
1350ce8ad6
commit
99b3c11ce2
|
@ -2536,7 +2536,8 @@ class TestInRepoConfig(ZuulTestCase):
|
|||
self.assertEqual(A.data['status'], 'NEW')
|
||||
self.assertEqual(A.reported, 1,
|
||||
"A should report failure")
|
||||
self.assertIn('Unknown projects: does-not-exist', A.messages[0],
|
||||
self.assertIn('The project "does-not-exist" was not found',
|
||||
A.messages[0],
|
||||
"A should have a syntax error reported")
|
||||
|
||||
def test_required_project_not_found_multiple_error(self):
|
||||
|
@ -2561,8 +2562,10 @@ class TestInRepoConfig(ZuulTestCase):
|
|||
self.assertEqual(A.data['status'], 'NEW')
|
||||
self.assertEqual(A.reported, 1,
|
||||
"A should report failure")
|
||||
self.assertIn('Unknown projects: does-not-exist, also-does-not-exist',
|
||||
A.messages[0], "A should have a syntax error reported")
|
||||
self.assertIn('The projects "does-not-exist", '
|
||||
'"also-does-not-exist" were not found.',
|
||||
A.messages[0],
|
||||
"A should have a syntax error reported")
|
||||
|
||||
def test_template_not_found_error(self):
|
||||
in_repo_conf = textwrap.dedent(
|
||||
|
|
|
@ -851,8 +851,7 @@ class JobParser(object):
|
|||
# exception only once to capture all of them in the
|
||||
# error message.
|
||||
if unknown_projects:
|
||||
names = ", ".join(unknown_projects)
|
||||
raise Exception("Unknown projects: %s" % (names,))
|
||||
raise ProjectNotFoundError(unknown_projects)
|
||||
|
||||
job.required_projects = new_projects
|
||||
|
||||
|
@ -925,7 +924,7 @@ class JobParser(object):
|
|||
for p in as_list(allowed_projects):
|
||||
(trusted, project) = self.pcontext.tenant.getProject(p)
|
||||
if project is None:
|
||||
raise Exception("Unknown project %s" % (p,))
|
||||
raise ProjectNotFoundError(p)
|
||||
allowed.append(project.name)
|
||||
job.allowed_projects = frozenset(allowed)
|
||||
|
||||
|
|
|
@ -216,12 +216,25 @@ class ProjectNotFoundError(ConfigurationSyntaxError):
|
|||
zuul_error_name = 'Project Not Found'
|
||||
|
||||
def __init__(self, project):
|
||||
message = textwrap.dedent("""\
|
||||
projects = None
|
||||
if isinstance(project, (list, tuple)):
|
||||
if len(project) > 1:
|
||||
projects = ', '.join(f'"{p}"' for p in project)
|
||||
else:
|
||||
project = project[0]
|
||||
if projects:
|
||||
message = textwrap.dedent(f"""\
|
||||
The projects {projects} were not found. All projects
|
||||
referenced within a Zuul configuration must first be
|
||||
added to the main configuration file by the Zuul
|
||||
administrator.""")
|
||||
else:
|
||||
message = textwrap.dedent(f"""\
|
||||
The project "{project}" was not found. All projects
|
||||
referenced within a Zuul configuration must first be
|
||||
added to the main configuration file by the Zuul
|
||||
administrator.""")
|
||||
message = textwrap.fill(message.format(project=project))
|
||||
message = textwrap.fill(message)
|
||||
super(ProjectNotFoundError, self).__init__(message)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue