Skip to content

Commit a1bfe7d

Browse files
committed
handling for empty string
1 parent 482e2d0 commit a1bfe7d

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

roboflow/core/project.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -345,20 +345,29 @@ def __annotation_upload(self, annotation_path: str, image_id: str):
345345
:param image_id: image id you'd like to upload that has annotations for it.
346346
"""
347347

348+
# stop on empty string
349+
if len(annotation_path) == 0:
350+
print("Please provide a non-empty string for annotation_path.")
351+
return {"result": "Please provide a non-empty string for annotation_path."}
352+
348353
# check if annotation file exists
349-
if os.path.exists(annotation_path):
354+
elif os.path.exists(annotation_path):
350355
print("-> found given annotation file")
351356
annotation_string = open(annotation_path, "r").read()
352357

353358
# if not annotation file, check if user wants to upload regular as classification annotation
354-
elif self.type == "classification" and type(annotation_path) == str:
359+
elif self.type == "classification":
355360
print(f"-> using {annotation_path} as classname for classification project")
356361
annotation_string = annotation_path
357362

358363
# don't attempt upload otherwise
359364
else:
360-
print("file not found and project type not classification")
361-
return {"result": "file not found and project type not classification"}
365+
print(
366+
"File not found or uploading to non-classification type project with invalid string"
367+
)
368+
return {
369+
"result": "File not found or uploading to non-classification type project with invalid string"
370+
}
362371

363372
# Set annotation upload url
364373
self.annotation_upload_url = "".join(
@@ -555,7 +564,12 @@ def single_upload(
555564
annotation_success = False
556565
# Give user warning that annotation failed to upload
557566
if not annotation_success:
558-
warnings.warn("Annotation, " + annotation_path + ", failed to upload!")
567+
warnings.warn(
568+
"Annotation, "
569+
+ annotation_path
570+
+ "failed to upload!\n Upload correct annotation file to image_id: "
571+
+ image_id
572+
)
559573
else:
560574
annotation_success = True
561575

0 commit comments

Comments
 (0)