issue.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # Copyright 2021-2024 Avaiga Private Limited
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
  4. # the License. You may obtain a copy of the License at
  5. #
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. #
  8. # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
  9. # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
  10. # specific language governing permissions and limitations under the License.
  11. from dataclasses import dataclass
  12. from typing import Any, Optional
  13. @dataclass
  14. class Issue:
  15. """An issue detected in the configuration.
  16. `Issue` is a dataclass that represents an issue detected during the configuration check
  17. process. It contains the necessary information to understand the issue and help the user to fix
  18. it.
  19. Attributes:
  20. level (str): Level of the issue among ERROR, WARNING, INFO.
  21. field (str): Configuration field on which the issue has been detected.
  22. value (Any): Value of the field on which the issue has been detected.
  23. message (str): Human readable message to help the user fix the issue.
  24. tag (Optional[str]): Optional tag to be used to filter issues.
  25. """
  26. level: str
  27. field: str
  28. value: Any
  29. message: str
  30. tag: Optional[str]
  31. def __str__(self) -> str:
  32. message = self.message
  33. if self.value:
  34. current_value_str = f'"{self.value}"' if isinstance(self.value, str) else f"{self.value}"
  35. message += f" Current value of property `{self.field}` is {current_value_str}."
  36. return message