Skip to content

Commit 26f2848

Browse files
liqulCopilot
andauthored
Update taskweaver/ext_role/image_reader/image_reader.py
Co-authored-by: Copilot <[email protected]>
1 parent e27a9ca commit 26f2848

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

taskweaver/ext_role/image_reader/image_reader.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,16 @@ def local_image_to_data_url(image_path):
2323
if mime_type is None:
2424
mime_type = "application/octet-stream" # Default MIME type if none is found
2525

26-
# Read and encode the image file
27-
with open(image_path, "rb") as image_file:
28-
base64_encoded_data = base64.b64encode(image_file.read()).decode("utf-8")
29-
26+
try:
27+
# Read and encode the image file
28+
with open(image_path, "rb") as image_file:
29+
base64_encoded_data = base64.b64encode(image_file.read()).decode("utf-8")
30+
except FileNotFoundError:
31+
print(f"Error: The file {image_path} does not exist.")
32+
return None
33+
except IOError:
34+
print(f"Error: The file {image_path} could not be read.")
35+
return None
3036
# Construct the data URL
3137
return f"data:{mime_type};base64,{base64_encoded_data}"
3238

0 commit comments

Comments
 (0)