fix: Enhance error handling and logging across multiple evaluators
- Added logging for file retrieval and error handling in file.py, improving robustness during file operations. - Implemented checks for file existence and parsing errors in general.py, enhancing reliability in JSON/YAML processing. - Improved table comparison logic in table.py with detailed error logging for sheet loading and cell value reading. - Enhanced metrics evaluation in slides.py with additional checks for paragraph and run counts, ensuring thorough comparison. - Updated utils.py to include file existence checks and detailed error logging during cell value reading.
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
import os
|
||||
import logging
|
||||
from typing import Dict, List, Set
|
||||
from typing import Optional, Any, Union
|
||||
from datetime import datetime
|
||||
import requests
|
||||
import pandas as pd
|
||||
|
||||
logger = logging.getLogger("desktopenv.getter.file")
|
||||
|
||||
|
||||
def get_content_from_vm_file(env, config: Dict[str, Any]) -> Any:
|
||||
"""
|
||||
@@ -101,16 +104,42 @@ def get_vm_file(env, config: Dict[str, Any]) -> Union[Optional[str], List[Option
|
||||
|
||||
for i, (p, d) in enumerate(zip(paths, dests)):
|
||||
_path = os.path.join(env.cache_dir, d)
|
||||
file = env.controller.get_file(p)
|
||||
if file is None:
|
||||
|
||||
try:
|
||||
# Try to get file from VM
|
||||
file = env.controller.get_file(p)
|
||||
if file is None:
|
||||
logger.warning(f"Failed to get file from VM: {p}")
|
||||
if i in gives:
|
||||
cache_paths.append(None)
|
||||
continue
|
||||
|
||||
if i in gives:
|
||||
cache_paths.append(_path)
|
||||
|
||||
# Write file with robust error handling
|
||||
try:
|
||||
# Ensure cache directory exists
|
||||
os.makedirs(env.cache_dir, exist_ok=True)
|
||||
|
||||
with open(_path, "wb") as f:
|
||||
f.write(file)
|
||||
logger.info(f"Successfully saved file: {_path} ({len(file)} bytes)")
|
||||
|
||||
except IOError as e:
|
||||
logger.error(f"IO error writing file {_path}: {e}")
|
||||
if i in gives:
|
||||
cache_paths[-1] = None # Replace the path we just added with None
|
||||
except Exception as e:
|
||||
logger.error(f"Unexpected error writing file {_path}: {e}")
|
||||
if i in gives:
|
||||
cache_paths[-1] = None
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error processing file {p}: {e}")
|
||||
if i in gives:
|
||||
cache_paths.append(None)
|
||||
continue
|
||||
|
||||
if i in gives:
|
||||
cache_paths.append(_path)
|
||||
with open(_path, "wb") as f:
|
||||
f.write(file)
|
||||
|
||||
return cache_paths[0] if len(cache_paths)==1 else cache_paths
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user