Skip to content

Fix garbled Chinese log messages, bare except clauses, and unsafe empty-list access in EIS processing#1

Merged
Sunnnnch merged 5 commits into
mainfrom
copilot/check-current-repo-issues
Mar 11, 2026
Merged

Fix garbled Chinese log messages, bare except clauses, and unsafe empty-list access in EIS processing#1
Sunnnnch merged 5 commits into
mainfrom
copilot/check-current-repo-issues

Conversation

Copilot AI commented Mar 11, 2026

Copy link
Copy Markdown
Contributor

Repository audit found ~20 corrupted Chinese strings in get_ir_from_eis(), unsafe bare except: clauses across 4 files, and a potential crash when _filter_outliers() returns empty lists.

Garbled Chinese text in processing_lsv.py

All log messages in get_ir_from_eis() had corrupted characters rendering them unreadable. Reconstructed with correct Chinese and switched from print() to log().

# Before (garbled)
print(f"成功读取 {filepath}高频区选取 ????")
print(f"???频率范围: Z'={ir_value:.3f}Ω, Z''={z_imag[i]:.3f}?")

# After
log(f"无法读取文件 {filepath}, 所有编码均失败")
log(f"全局最小虚部: Z'={ir_value:.3f}Ω, Z''={z_imag[i]:.3f}Ω")

Empty-list guard after _filter_outliers()

_filter_outliers() can return empty lists, causing ValueError on subsequent min()/max() calls. Added a guard that skips the entire high-frequency analysis block when filtered data is empty.

Bare except: → typed exceptions

8 bare except: clauses (which swallow KeyboardInterrupt, SystemExit, etc.) replaced across processing_cv.py, processing_eis.py, processing_ecsa.py, tool_executor.py with except Exception: or except (ValueError, TypeError): as appropriate.

Debug print()logging.debug()

3 print(f"[DEBUG] ...") calls in agent_controller.py and tool_executor.py replaced with _logger.debug(). 10 additional print() calls in the Tafel export section of processing_lsv.py converted to log() for consistency.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits March 11, 2026 04:39
…t debug prints to logging

- Fix ~20 garbled/corrupted Chinese print messages in processing_lsv.py get_ir_from_eis()
- Add empty-list guard after _filter_outliers() to prevent potential crash
- Convert all print() calls to log() in processing_lsv.py for consistent logging
- Replace 8 bare except: clauses with except Exception: or except (ValueError, TypeError):
  in processing_cv.py, processing_eis.py, processing_ecsa.py, tool_executor.py
- Replace debug print() statements with logging.debug() in agent_controller.py and tool_executor.py

Co-authored-by: Sunnnnch <147936020+Sunnnnch@users.noreply.github.com>
Address code review feedback: restructure the empty-list guard after
_filter_outliers() so it properly protects the entire high-frequency
analysis block, not just the log message.

Co-authored-by: Sunnnnch <147936020+Sunnnnch@users.noreply.github.com>
Copilot AI changed the title [WIP] Check for issues in current repository Fix garbled Chinese log messages, bare except clauses, and debug prints in production code Mar 11, 2026
Copilot AI changed the title Fix garbled Chinese log messages, bare except clauses, and debug prints in production code Fix garbled Chinese log messages, bare except clauses, and unsafe empty-list access in EIS processing Mar 11, 2026
John Doe added 2 commits March 11, 2026 13:46
- Remove LLM API key from log output (routes_post)
- Add path traversal protection (tool_executor, vision_client, routes_post)
- Add safe integer parsing with clamping (routes_get)
- Add parameter whitelist validation for sort_by/chart_type (routes_get)
- Add CSP and X-Content-Type-Options headers (http_server)
- Fix _sanitize_filename directory traversal via os.path.basename (processing_core_v6)
- Add .bak backup before JSON writes (history, projects)
- Replace silent exception swallowing with logging (projects)
- Fix matplotlib figure leak with try-finally (processing_lsv)
- Fix garbled error message in request_utils
- Extract shared utils (as_float/as_int/as_bool) to eliminate duplication
- Add centralized path_security module
- Pin dependency version ranges (requirements-pack)
…s, improve robustness

- Split tool_executor.py (860 lines) into thin dispatcher + tools_data.py + tools_projects.py
- Add project name validation (length limit 128, control char stripping) in store/projects.py
- Extract magic numbers to named constants in processing_lsv.py (MAD thresholds, fitting defaults, EIS thresholds, SOFTWARE_VERSION)
- Add shared read_file_with_fallback_encodings() utility to core/utils.py
- Replace inline encoding loops in processing_cv/eis/lsv with shared utility
- Fix bare except blocks: narrow to (ValueError, TypeError) in LSV Tafel fitting, parse helpers
- Add try-finally around plt.savefig in CV, EIS (Nyquist+Bode), LSV IR-compensated plots
- Fix CV peaks bare except to log instead of silently swallowing
- Add 17 tests for path_security module
- Add 17+ tests for utils module (as_float, as_int, as_bool, read_file_with_fallback_encodings)
- Add 11 tests for project input validation

All 103 tests pass (92 existing + 11 new validation tests).
@Sunnnnch
Sunnnnch merged commit 21536ce into main Mar 11, 2026
0 of 2 checks passed
@Sunnnnch
Sunnnnch deleted the copilot/check-current-repo-issues branch March 11, 2026 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants