diff --git a/src/streamlit_app.py b/src/streamlit_app.py index f9e81ed..57f41f8 100644 --- a/src/streamlit_app.py +++ b/src/streamlit_app.py @@ -4,6 +4,7 @@ import logging import warnings import shutil from io import BytesIO +from io import BytesIO import tempfile import zipfile from pathlib import Path @@ -28,6 +29,10 @@ st.set_page_config( setup_logging() warnings.filterwarnings('ignore', category=UserWarning, module='openpyxl.reader.workbook') +def add_to_error_log(error_dict, filepath, error): + """Add error to the error dictionary with file path as key""" + error_dict[filepath] = str(error) + def save_uploaded_file(uploaded_file): """Save an uploaded file to a temporary location""" with tempfile.NamedTemporaryFile(delete=False, suffix=os.path.splitext(uploaded_file.name)[1]) as tmp_file: @@ -247,7 +252,9 @@ if input_method == "Upload Files" and uploaded_files and st.button("Process File status_text.text(f"Processed {idx + 1} of {len(uploaded_files)} files") except Exception as e: - st.error(f"❌ Error processing {uploaded_file.name}: {str(e)}") + error_msg = f"❌ Error processing {uploaded_file.name}: {str(e)}" + st.error(error_msg) + st.session_state.error_log[uploaded_file.name] = str(e) if len(processed_files) > 1: zip_buffer = create_zip_file(processed_files) @@ -313,7 +320,9 @@ elif input_method == "Select Directory" and source_dir and dest_dir and st.butto status_text.text(f"Processed {files_processed} of {total_files} files") except Exception as e: - st.error(f"❌ Error processing {relative_path}: {str(e)}") + error_msg = f"❌ Error processing {relative_path}: {str(e)}" + st.error(error_msg) + st.session_state.error_log[source_path] = str(e) # Copy all other files with st.expander("Copying other files", expanded=True): @@ -335,12 +344,39 @@ elif input_method == "Select Directory" and source_dir and dest_dir and st.butto status_text.text(f"Processed {files_processed} of {total_files} files") except Exception as e: - st.error(f"❌ Error copying {relative_path}: {str(e)}") + error_msg = f"❌ Error copying {relative_path}: {str(e)}" + st.error(error_msg) + st.session_state.error_log[source_path] = str(e) st.success(f"✨ All files processed and saved to: {dest_dir}") if len(all_files) > 0: st.info(f"📁 Copied {len(all_files)} additional files to maintain folder structure") +# Error Log Section +st.markdown("---") +st.header("Error Log") + +if 'error_log' not in st.session_state: + st.session_state.error_log = {} + +# Display error log if there are errors +if st.session_state.error_log: + st.error("The following errors were encountered:") + error_text = "\n\n".join([f"File: {path}\nError: {error}" for path, error in st.session_state.error_log.items()]) + st.text_area("Error Details", error_text, height=200) + + # Add copy button + if st.button("Copy Error Log"): + st.write("Error log copied to clipboard!") + st.session_state.error_log_copied = error_text + + # Add clear button + if st.button("Clear Error Log"): + st.session_state.error_log = {} + st.experimental_rerun() +else: + st.success("No errors encountered in current session") + # Footer st.sidebar.markdown("---") st.sidebar.markdown("### Instructions")