Skip to content

Commit ed157cc

Browse files
author
Val Brodsky
committed
Handle out of band exceptions for Project add_model_config in order to deal with a model_setup_complete scenario
1 parent 88ba72e commit ed157cc

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

libs/labelbox/src/labelbox/schema/project.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import re
12
import json
23
import logging
34
from string import Template
@@ -1268,7 +1269,22 @@ def add_model_config(self, model_config_id: str) -> str:
12681269
"projectId": self.uid,
12691270
"modelConfigId": model_config_id,
12701271
}
1271-
result = self.client.execute(query, params)
1272+
try:
1273+
result = self.client.execute(query, params)
1274+
except LabelboxError as e:
1275+
# unfortunately, this is the type of errors our client does not deal with and so the error message is not in the same format as the other errors
1276+
# needs custom parsing
1277+
error_string = e.message
1278+
# Regex to find the message content
1279+
pattern = r"'message': '([^']+)'"
1280+
# Search for the pattern in the error string
1281+
match = re.search(pattern, error_string)
1282+
if match:
1283+
error_content = match.group(1)
1284+
else:
1285+
error_content = "Unknown error"
1286+
raise LabelboxError(message=error_content) from e
1287+
12721288
if not result:
12731289
raise ResourceNotFoundError(ModelConfig, params)
12741290
return result["createProjectModelConfig"]["projectModelConfigId"]

0 commit comments

Comments
 (0)