From ee069c0a62a4f3ccde95cefd3e8f985f69d611f9 Mon Sep 17 00:00:00 2001 From: haosenwang1018 Date: Wed, 25 Feb 2026 04:11:15 +0000 Subject: [PATCH] fix: replace 3 bare excepts with specific exception types - llm_inference.py: catch (ValueError, TypeError) for int() conversions of bpm and duration metadata fields - gemini_caption.py: catch (json.JSONDecodeError, ValueError) for json.loads() parsing Bare `except:` catches KeyboardInterrupt and SystemExit, which can mask real errors. Using specific exceptions is safer and clearer. --- acestep/llm_inference.py | 4 ++-- scripts/lora_data_prepare/gemini_caption.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/acestep/llm_inference.py b/acestep/llm_inference.py index 07a8165e..d7925806 100644 --- a/acestep/llm_inference.py +++ b/acestep/llm_inference.py @@ -2602,7 +2602,7 @@ def save_current_field(): if current_key == 'bpm': try: metadata['bpm'] = int(value.strip()) - except: + except (ValueError, TypeError): metadata['bpm'] = value.strip() elif current_key == 'caption': # Post-process caption to remove YAML multi-line formatting @@ -2610,7 +2610,7 @@ def save_current_field(): elif current_key == 'duration': try: metadata['duration'] = int(value.strip()) - except: + except (ValueError, TypeError): metadata['duration'] = value.strip() elif current_key == 'genres': metadata['genres'] = value.strip() diff --git a/scripts/lora_data_prepare/gemini_caption.py b/scripts/lora_data_prepare/gemini_caption.py index 473092b2..ec19e2dd 100644 --- a/scripts/lora_data_prepare/gemini_caption.py +++ b/scripts/lora_data_prepare/gemini_caption.py @@ -473,7 +473,7 @@ def analysis_audio_by_gemini( ) try: json_result = json.loads(result) - except: + except (json.JSONDecodeError, ValueError): json_result = extract_json_from_text(result) if json_result is None: raise Exception(f"无法解析json, {result}")