exceptions.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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 typing import List, Optional
  12. class ConfigCoreVersionMismatched(Exception):
  13. """Raised if core version in Config does not match with the version of Taipy Core."""
  14. def __init__(self, config_core_version: str, core_version: str) -> None:
  15. self.message = (
  16. f"Core version {config_core_version} in Config does not match with version of Taipy Core {core_version}."
  17. )
  18. class CoreServiceIsAlreadyRunning(Exception):
  19. """Raised if the Core service is already running."""
  20. class CycleAlreadyExists(Exception):
  21. """Raised if it is trying to create a Cycle that has already exists."""
  22. class NonExistingCycle(Exception):
  23. """Raised if a requested cycle is not known by the Cycle manager."""
  24. def __init__(self, cycle_id: str):
  25. self.message = f"Cycle: {cycle_id} does not exist."
  26. class MissingRequiredProperty(Exception):
  27. """Raised if a required property is missing when creating a Data Node."""
  28. class InvalidDataNodeType(Exception):
  29. """Raised if a data node storage type does not exist."""
  30. class MultipleDataNodeFromSameConfigWithSameOwner(Exception):
  31. """
  32. Raised if there are multiple data nodes from the same data node configuration and the same owner identifier.
  33. """
  34. class NoData(Exception):
  35. """Raised if a data node is read before it has been written.
  36. This exception can be raised by `DataNode.read_or_raise()^`.
  37. """
  38. class UnknownDatabaseEngine(Exception):
  39. """Raised if the database engine is not known when creating a connection with a SQLDataNode."""
  40. class MissingAppendQueryBuilder(Exception):
  41. """Raised if no append query build is provided when appending data to a SQLDataNode."""
  42. class UnknownParquetEngine(Exception):
  43. """Raised if the parquet engine is not known or not supported when create a ParquetDataNode."""
  44. class UnknownCompressionAlgorithm(Exception):
  45. """Raised if the compression algorithm is not supported by ParquetDataNode."""
  46. class NonExistingDataNode(Exception):
  47. """Raised if a requested DataNode is not known by the DataNode Manager."""
  48. def __init__(self, data_node_id: str):
  49. self.message = f"DataNode: {data_node_id} does not exist."
  50. class DataNodeIsBeingEdited(Exception):
  51. """Raised if a DataNode is being edited."""
  52. def __init__(self, data_node_id: str, editor_id: Optional[str] = None):
  53. self.message = f"DataNode {data_node_id} is being edited{ ' by ' + editor_id if editor_id else ''}."
  54. class NonExistingDataNodeConfig(Exception):
  55. """Raised if a requested DataNodeConfig is not known by the DataNode Manager."""
  56. def __init__(self, data_node_config_id: str):
  57. self.message = f"Data node config: {data_node_config_id} does not exist."
  58. class NonExistingExcelSheet(Exception):
  59. """Raised if a requested Sheet name does not exist in the provided Excel file."""
  60. def __init__(self, sheet_name: str, excel_file_name: str):
  61. self.message = f"{sheet_name} does not exist in {excel_file_name}."
  62. class ExposedTypeLengthMismatch(Exception):
  63. """Raised if length of exposed type list does not match with number of sheets in the provided Excel file."""
  64. class SheetNameLengthMismatch(Exception):
  65. """Raised if length of sheet_name list does not match
  66. with number of sheets in the data to be written to Excel file."""
  67. class InvalidExposedType(Exception):
  68. """Raised if an invalid exposed type is provided."""
  69. class InvalidCustomDocument(Exception):
  70. """Raised if an invalid custom document class is provided to a `MongoCollectionDataNode`."""
  71. class DataNodeConfigIsNotGlobal(Exception):
  72. """Raised if a DataNode is not global."""
  73. def __init__(self, data_node_config_id: str):
  74. self.message = f"Data node config `{data_node_config_id}` does not have GLOBAL scope."
  75. class MissingReadFunction(Exception):
  76. """Raised if no read function is provided for the GenericDataNode."""
  77. class MissingWriteFunction(Exception):
  78. """Raised if no write function is provided for the GenericDataNode."""
  79. class JobNotDeletedException(RuntimeError):
  80. """Raised if there is an attempt to delete a job that cannot be deleted.
  81. This exception can be raised by `taipy.delete_job()^`.
  82. """
  83. def __init__(self, job_id: str):
  84. self.message = f"Job: {job_id} cannot be deleted."
  85. class NonExistingJob(RuntimeError):
  86. """Raised if a requested job is not known by the Job manager."""
  87. def __init__(self, job_id: str):
  88. self.message = f"Job: {job_id} does not exist."
  89. class SubmissionNotDeletedException(RuntimeError):
  90. """Raised if there is an attempt to delete a submission that cannot be deleted.
  91. This exception can be raised by `taipy.delete()^`.
  92. """
  93. def __init__(self, submission_id: str):
  94. self.message = f"Submission: {submission_id} cannot be deleted."
  95. class DataNodeWritingError(RuntimeError):
  96. """Raised if an error happens during the writing in a data node."""
  97. class InvalidSubscriber(RuntimeError):
  98. """Raised if the loaded function is not valid."""
  99. class InvalidSequenceId(Exception):
  100. """Raised if a Sequence id can not be broken down."""
  101. def __init__(self, sequence_id: str):
  102. self.message = f"Sequence: {sequence_id} is invalid."
  103. class InvalidSequence(Exception):
  104. """Raised if a Sequence is not a connected Directed Acyclic Graph."""
  105. def __init__(self, sequence_id: str):
  106. self.message = f"Sequence: {sequence_id} is not a connected Directed Acyclic Graph."
  107. class NonExistingSequence(Exception):
  108. """Raised if a requested Sequence is not known by the Sequence Manager."""
  109. def __init__(self, sequence_id: str, scenario_id: str=None):
  110. if scenario_id:
  111. self.message = f"Sequence: {sequence_id} does not exist in scenario {scenario_id}."
  112. else:
  113. self.message = f"Sequence: {sequence_id} does not exist."
  114. class SequenceAlreadyExists(Exception):
  115. """Raised if a Sequence already exists."""
  116. def __init__(self, sequence_name: str, scenario_id: str):
  117. self.message = f"Sequence: {sequence_name} already exists in scenario {scenario_id}."
  118. class SequenceBelongsToNonExistingScenario(Exception):
  119. """Raised if a Sequence does not belong to an existing Scenario."""
  120. def __init__(self, sequence_id: str, scenario_id: str):
  121. self.message = f"Sequence: {sequence_id} belongs to a non-existing Scenario: {scenario_id}."
  122. class SequenceTaskDoesNotExistInScenario(Exception):
  123. """Raised if Tasks of a Sequence do not exist in the same Scenario that the Sequence belongs to."""
  124. def __init__(self, task_ids: List[Optional[str]], sequence_name: str, scenario_id: str):
  125. self.message = f"Tasks {task_ids} of Sequence {sequence_name} does not exist in Scenario {scenario_id}."
  126. class SequenceTaskConfigDoesNotExistInSameScenarioConfig(Exception):
  127. """Raised if TaskConfigs of a Sequence do not exist in the same ScenarioConfig that the Sequence belongs to."""
  128. def __init__(self, task_config_ids: List[Optional[str]], sequence_name: str, scenario_config_id: str):
  129. self.message = f"TaskConfig {task_config_ids} of Sequence name {sequence_name} "
  130. self.message += f"does not exist in ScenarioConfig {scenario_config_id}."
  131. class NonExistingSequenceConfig(Exception):
  132. """Raised if a requested Sequence configuration is not known by the Sequence Manager."""
  133. def __init__(self, sequence_config_id: str):
  134. self.message = f"Sequence config: {sequence_config_id} does not exist."
  135. class MultipleSequenceFromSameConfigWithSameOwner(Exception):
  136. """Raised if it exists multiple sequences from the same sequence config and with the same _owner_id_."""
  137. class ModelNotFound(Exception):
  138. """Raised when trying to fetch a non-existent model.
  139. This exception can be raised by `taipy.get()^` and `taipy.delete()^`.
  140. """
  141. def __init__(self, model_name: str, model_id: str):
  142. self.message = f"A {model_name} model with id {model_id} could not be found."
  143. class NonExistingScenario(Exception):
  144. """Raised if a requested scenario is not known by the Scenario Manager."""
  145. def __init__(self, scenario_id: str):
  146. self.message = f"Scenario: {scenario_id} does not exist."
  147. class NonExistingScenarioConfig(Exception):
  148. """Raised if a requested scenario configuration is not known by the Scenario Manager.
  149. This exception can be raised by `taipy.compare_scenarios()^`.
  150. """
  151. def __init__(self, scenario_config_id: str):
  152. self.message = f"Scenario config: {scenario_config_id} does not exist."
  153. class InvalidSscenario(Exception):
  154. """Raised if a Scenario is not a Directed Acyclic Graph."""
  155. def __init__(self, scenario_id: str):
  156. self.message = f"Scenario: {scenario_id} is not a Directed Acyclic Graph."
  157. class DoesNotBelongToACycle(Exception):
  158. """Raised if a scenario without any cycle is promoted as primary scenario."""
  159. class DeletingPrimaryScenario(Exception):
  160. """Raised if a primary scenario is deleted."""
  161. class DifferentScenarioConfigs(Exception):
  162. """Raised if scenario comparison is requested on scenarios with different scenario configs.
  163. This exception can be raised by `taipy.compare_scenarios()^`.
  164. """
  165. class InsufficientScenarioToCompare(Exception):
  166. """Raised if too few scenarios are requested to be compared.
  167. Scenario comparison need at least two scenarios to compare.
  168. This exception can be raised by `taipy.compare_scenarios()^`.
  169. """
  170. class NonExistingComparator(Exception):
  171. """Raised if a scenario comparator does not exist.
  172. This exception can be raised by `taipy.compare_scenarios()^`.
  173. """
  174. class UnauthorizedTagError(Exception):
  175. """Must provide an authorized tag."""
  176. class DependencyNotInstalled(Exception):
  177. """Raised if a package is missing."""
  178. def __init__(self, package_name: str):
  179. self.message = f"""
  180. Package '{package_name}' should be installed.
  181. Run 'pip install taipy[{package_name}]' to installed it.
  182. """
  183. class NonExistingTask(Exception):
  184. """Raised if a requested task is not known by the Task Manager."""
  185. def __init__(self, task_id: str):
  186. self.message = f"Task: {task_id} does not exist."
  187. class NonExistingTaskConfig(Exception):
  188. """Raised if a requested task configuration is not known by the Task Manager."""
  189. def __init__(self, id: str):
  190. self.message = f"Task config: {id} does not exist."
  191. class MultipleTaskFromSameConfigWithSameOwner(Exception):
  192. """Raised if there are multiple tasks from the same task configuration and the same owner identifier."""
  193. class OrchestratorNotBuilt(Exception):
  194. """Raised if the orchestrator was not built in the OrchestratorFactory"""
  195. class ModeNotAvailable(Exception):
  196. """Raised if the mode in JobConfig is not supported."""
  197. class InvalidExportPath(Exception):
  198. """Raised if the export path is not valid."""
  199. class NonExistingVersion(Exception):
  200. """Raised if request a Version that is not known by the Version Manager."""
  201. def __init__(self, version_number: str):
  202. self.message = f"Version '{version_number}' does not exist."
  203. class VersionIsNotProductionVersion(Exception):
  204. """Raised if the version is not a production version."""
  205. class ConflictedConfigurationError(Exception):
  206. """Conflicts have been detected between the current and previous Configurations."""
  207. class InvalidEventAttributeName(Exception):
  208. """
  209. Raised if the attribute doesn't exist or an attribute name is provided
  210. when operation is either creation, deletion or submission
  211. """
  212. class InvalidEventOperation(Exception):
  213. """Raised when operation doesn't belong to the entity"""
  214. class FileCannotBeRead(Exception):
  215. """Raised when a file cannot be read."""
  216. class _SuspiciousFileOperation(Exception):
  217. pass