A programming framework for agentic AI
Fixes an error that can occur when listing the contents of a directory. (#5938)
afourney84c622a4cc50
diff --git a/python/packages/autogen-ext/src/autogen_ext/agents/file_surfer/_markdown_file_browser.py b/python/packages/autogen-ext/src/autogen_ext/agents/file_surfer/_markdown_file_browser.pyindex 3cf499a20..e904e2be9 100644--- a/python/packages/autogen-ext/src/autogen_ext/agents/file_surfer/_markdown_file_browser.py+++ b/python/packages/autogen-ext/src/autogen_ext/agents/file_surfer/_markdown_file_browser.py@@ -245,12 +245,22 @@ class MarkdownFileBrowser:for entry in os.listdir(local_path):size = ""full_path = os.path.join(local_path, entry)- mtime = datetime.datetime.fromtimestamp(os.path.getmtime(full_path)).strftime("%Y-%m-%d %H:%M")++ mtime = ""+ try:+ mtime = datetime.datetime.fromtimestamp(os.path.getmtime(full_path)).strftime("%Y-%m-%d %H:%M")+ except Exception as e:+ # Handles PermissionError, etc.+ mtime = f"N/A: {type(e).__name__}"if os.path.isdir(full_path):entry = entry + os.path.sepelse:- size = str(os.path.getsize(full_path))+ try:+ size = str(os.path.getsize(full_path))+ except Exception as e:+ # Handles PermissionError, etc.+ size = f"N/A: {type(e).__name__}"listing += f"| {entry} | {size} | {mtime} |\n"return listing