-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AutoinstallValidationError: An error for autoinstall validation failures
Adds a special exception for Autoinstall related failures and a specific implementation for autoinstall validation failures. When a user passes incorrect autoinstall data, the generated bug report will be titled: "Autoinstall crashed with AutoinstallValidationError" Where the traceback will start with a hint on the offending section. For example: "Malformed autoinstall in 'apt' section" Information from the original jsonschema ValidationError is also available in the traceback to point to specific issues with the provided data. The section reporting is a little crude in the validation of the base schema done by SubiquityServer, which can't discern between the 'interative-sessions' and 'version' keys, but for now the scope is pretty limited and can be fixed up at a later time.
- Loading branch information
1 parent
e29a2a6
commit 34ffe1f
Showing
7 changed files
with
172 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Copyright 2024 Canonical, Ltd. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
import logging | ||
|
||
from jsonschema.exceptions import ValidationError | ||
|
||
log = logging.getLogger("subiquity.server.autoinstall") | ||
|
||
|
||
class AutoinstallError(Exception): | ||
def __init__( | ||
self, | ||
message: str, | ||
): | ||
super().__init__(message) | ||
self.message = message | ||
|
||
def __repr__(self): | ||
return f"<{self.__class__.__name__}: {self.message!r}>" | ||
|
||
def __str__(self): | ||
return self.__repr__() | ||
|
||
|
||
class AutoinstallValidationError(AutoinstallError): | ||
def __init__( | ||
self, | ||
owner: str, | ||
error: ValidationError, | ||
**kwargs, | ||
): | ||
self.message = f"Malformed autoinstall in {owner!r} section" | ||
self.owner = owner | ||
self.error = error | ||
super().__init__(self.message, **kwargs) | ||
|
||
def __str__(self): | ||
return f"{self.message}\n\n{self.error}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters