Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions acestep/llm_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -2602,15 +2602,15 @@ 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
metadata['caption'] = MetadataConstrainedLogitsProcessor.postprocess_caption(value)
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()
Expand Down
2 changes: 1 addition & 1 deletion scripts/lora_data_prepare/gemini_caption.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Comment on lines 474 to 477
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

TypeError regression: result=None now causes an unhandled exception

_gemini_service.analyze_audio() returns None on several code paths (API failure, extraction failure, etc.). When result is None, json.loads(None) raises TypeError: the JSON object must be str, bytes or bytearray, not NoneType, which is not caught by the new except (json.JSONDecodeError, ValueError) clause. The bare except: this replaces would have caught it and fallen through to extract_json_from_text(result)None → the proper raise Exception(...) at line 479.

🐛 Proposed fix — add `TypeError` and guard against `None`
+    if result is None:
+        raise Exception("无法解析json, 无响应结果")
     try:
         json_result = json.loads(result)
-    except (json.JSONDecodeError, ValueError):
+    except (ValueError, TypeError):
         json_result = extract_json_from_text(result)

Note: json.JSONDecodeError is a subclass of ValueError, so ValueError alone covers both. TypeError handles the None/non-string case.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/lora_data_prepare/gemini_caption.py` around lines 474 - 477, The
try/except around json.loads(result) must handle result==None and non-string
inputs from _gemini_service.analyze_audio; update the block in gemini_caption.py
so you either pre-guard (if result is None or not isinstance(result, (str,
bytes, bytearray)): json_result = extract_json_from_text(result)) or expand the
except to include TypeError (or ValueError and TypeError) so json.loads won't
raise an unhandled TypeError; keep using extract_json_from_text(result) as the
fallback and preserve the later raise Exception(...) behavior.

if json_result is None:
raise Exception(f"无法解析json, {result}")
Expand Down