exceptions.py 13 KB

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