|
14 | 14 | from kili.domain.project import ProjectId |
15 | 15 | from kili.domain.types import ListOrTuple |
16 | 16 | from kili.domain.user import UserId |
| 17 | +from kili.exceptions import GraphQLError |
17 | 18 | from kili.use_cases.asset.utils import AssetUseCasesUtils |
18 | 19 | from kili.use_cases.base import BaseUseCases |
19 | 20 | from kili.utils.labels.parsing import parse_labels |
|
25 | 26 | import pandas as pd |
26 | 27 |
|
27 | 28 |
|
| 29 | +LOCK_ERRORS = { |
| 30 | + "AlreadyHaveLabelOnCurrentStep": "You cannot edit this asset as you've already submitted a label.", |
| 31 | + "AssetAlreadyAssigned": "This asset is assigned to someone else. You cannot edit it.", |
| 32 | + "AssetAlreadyLocked": "This asset is currently being edited by another user.", |
| 33 | + "AssetInDoneStepStatus": "This asset is already labeled or reviewed and cannot be edited.", |
| 34 | + "AssetInDoneStepStatusWithCorrectAction": "You already labeled this asset, but you can still correct it.", |
| 35 | + "AssetInDoneStepStatusWithReviewAction": "This asset is completed. Take it for review to make changes.", |
| 36 | + "AssetInNextStepWithCorrectAction": "This asset is awaiting to be reviewed but can still be corrected.", |
| 37 | + "AssetLockedNoReason": "This asset is currently locked. You cannot edit it.", |
| 38 | + "BlockedByEnforceStepSeparation": "You can't edit this asset as you already worked on another step.", |
| 39 | + "LabelNotEditable": "This label was created in another step and is read-only.", |
| 40 | + "NotAssignedWithAssignAction": "This asset is in read-only mode because you are not assigned to it." |
| 41 | + + "To make edits, add yourself as an assignee.", |
| 42 | + "NotInStepAssignees": "You cannot edit this asset in its current step.", |
| 43 | +} |
| 44 | + |
| 45 | + |
28 | 46 | class LabelUseCases(BaseUseCases): |
29 | 47 | """Label use cases.""" |
30 | 48 |
|
@@ -116,12 +134,20 @@ def append_labels( |
116 | 134 | overwrite=overwrite, |
117 | 135 | labels_data=labels_to_add, |
118 | 136 | ) |
119 | | - return self._kili_api_gateway.append_many_labels( |
120 | | - fields=fields, |
121 | | - disable_tqdm=disable_tqdm, |
122 | | - data=data, |
123 | | - project_id=project_id, |
124 | | - ) |
| 137 | + try: |
| 138 | + return self._kili_api_gateway.append_many_labels( |
| 139 | + fields=fields, |
| 140 | + disable_tqdm=disable_tqdm, |
| 141 | + data=data, |
| 142 | + project_id=project_id, |
| 143 | + ) |
| 144 | + except GraphQLError as e: |
| 145 | + if e.context and e.context.get("reason"): |
| 146 | + reason = e.context.get("reason") |
| 147 | + if reason in LOCK_ERRORS: |
| 148 | + raise ValueError(LOCK_ERRORS[reason]) from e |
| 149 | + |
| 150 | + raise e |
125 | 151 |
|
126 | 152 | def append_to_labels( |
127 | 153 | self, |
|
0 commit comments