Load saved pattern outputs from files. Error handling: - Handles missing output files - Handles corrupted JSON files - Handles file read permissions - Initializes empty state if files don't exist
()
| 1075 | |
| 1076 | |
| 1077 | def load_saved_outputs(): |
| 1078 | """Load saved pattern outputs from files. |
| 1079 | |
| 1080 | Error handling: |
| 1081 | - Handles missing output files |
| 1082 | - Handles corrupted JSON files |
| 1083 | - Handles file read permissions |
| 1084 | - Initializes empty state if files don't exist |
| 1085 | """ |
| 1086 | logger.info("Loading saved outputs") |
| 1087 | outputs_dir = get_outputs_dir() |
| 1088 | output_logs_file = os.path.join(outputs_dir, "output_logs.json") |
| 1089 | starred_outputs_file = os.path.join(outputs_dir, "starred_outputs.json") |
| 1090 | |
| 1091 | try: |
| 1092 | # Load output logs |
| 1093 | if os.path.exists(output_logs_file): |
| 1094 | with open(output_logs_file, "r") as f: |
| 1095 | st.session_state.output_logs = json.load(f) |
| 1096 | logger.debug(f"Loaded output logs from {output_logs_file}") |
| 1097 | |
| 1098 | # Load starred outputs |
| 1099 | if os.path.exists(starred_outputs_file): |
| 1100 | with open(starred_outputs_file, "r") as f: |
| 1101 | st.session_state.starred_outputs = json.load(f) |
| 1102 | logger.debug(f"Loaded starred outputs from {starred_outputs_file}") |
| 1103 | |
| 1104 | except json.JSONDecodeError as e: |
| 1105 | error_msg = f"Error decoding saved outputs (corrupted files): {str(e)}" |
| 1106 | logger.error(error_msg) |
| 1107 | st.error(error_msg) |
| 1108 | # Initialize empty state |
| 1109 | st.session_state.output_logs = [] |
| 1110 | st.session_state.starred_outputs = [] |
| 1111 | except PermissionError as e: |
| 1112 | error_msg = f"Permission denied when loading outputs: {str(e)}" |
| 1113 | logger.error(error_msg) |
| 1114 | st.error(error_msg) |
| 1115 | except Exception as e: |
| 1116 | error_msg = f"Unexpected error loading saved outputs: {str(e)}" |
| 1117 | logger.error(error_msg) |
| 1118 | st.error(error_msg) |
| 1119 | # Initialize empty state |
| 1120 | st.session_state.output_logs = [] |
| 1121 | st.session_state.starred_outputs = [] |
| 1122 | |
| 1123 | |
| 1124 | def handle_star_name_input(log_index: int, name: str): |
no test coverage detected