branch: externals/ellama
commit d72767e9b841560774004f83ea670df6e304e389
Author: Sergey Kostyaev <[email protected]>
Commit: Sergey Kostyaev <[email protected]>

    Handle non-existent files in ellama-tools--read-file
    
    Added a check in the ellama-tools--read-file function to verify if the 
specified
    file exists before attempting to read it. If the file does not exist, the
    function now returns an error message instead of throwing an error. This
    improves the robustness of the function by gracefully handling cases where 
the
    input path is invalid.
---
 ellama-tools.el | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/ellama-tools.el b/ellama-tools.el
index ae676e44db..cf7fbf7518 100644
--- a/ellama-tools.el
+++ b/ellama-tools.el
@@ -176,9 +176,11 @@ otherwise."
 
 (defun ellama-tools--read-file (path)
   "Read the file located at the specified PATH."
-  (with-temp-buffer
-    (insert-file-contents-literally path)
-    (buffer-string)))
+  (if (not (file-exists-p path))
+      (format "File %s doesn't exists." path)
+    (with-temp-buffer
+      (insert-file-contents-literally path)
+      (buffer-string))))
 
 (defun ellama-tools-read-file (path)
   "Read the file located at the specified PATH."

Reply via email to