MCPcopy Create free account
hub / github.com/danielmiessler/Fabric / save_outputs

Function save_outputs

scripts/python_ui/streamlit.py:1037–1074  ·  view source on GitHub ↗

Save pattern outputs and starred outputs to files. Error handling: - Creates output directory if it doesn't exist - Handles file write permissions - Handles JSON serialization errors - Logs all errors for debugging

()

Source from the content-addressed store, hash-verified

1035
1036
1037def save_outputs():
1038 """Save pattern outputs and starred outputs to files.
1039
1040 Error handling:
1041 - Creates output directory if it doesn't exist
1042 - Handles file write permissions
1043 - Handles JSON serialization errors
1044 - Logs all errors for debugging
1045 """
1046 logger.info("Saving outputs to persistent storage")
1047 outputs_dir = get_outputs_dir()
1048
1049 output_logs_file = os.path.join(outputs_dir, "output_logs.json")
1050 starred_outputs_file = os.path.join(outputs_dir, "starred_outputs.json")
1051
1052 try:
1053 # Save output logs
1054 with open(output_logs_file, "w") as f:
1055 json.dump(st.session_state.output_logs, f, indent=2)
1056 logger.debug(f"Saved output logs to {output_logs_file}")
1057
1058 # Save starred outputs
1059 with open(starred_outputs_file, "w") as f:
1060 json.dump(st.session_state.starred_outputs, f, indent=2)
1061 logger.debug(f"Saved starred outputs to {starred_outputs_file}")
1062
1063 except PermissionError as e:
1064 error_msg = f"Permission denied when saving outputs: {str(e)}"
1065 logger.error(error_msg)
1066 st.error(error_msg)
1067 except json.JSONEncodeError as e:
1068 error_msg = f"Error encoding outputs to JSON: {str(e)}"
1069 logger.error(error_msg)
1070 st.error(error_msg)
1071 except Exception as e:
1072 error_msg = f"Unexpected error saving outputs: {str(e)}"
1073 logger.error(error_msg)
1074 st.error(error_msg)
1075
1076
1077def load_saved_outputs():

Callers 4

save_output_logFunction · 0.85
star_outputFunction · 0.85
unstar_outputFunction · 0.85
mainFunction · 0.85

Calls 1

get_outputs_dirFunction · 0.85

Tested by

no test coverage detected