@@ -93,13 +93,85 @@ def translate_file(
9393
9494 # Translate
9595 print ("\n ⏳ Translating..." )
96- translated = translator .translate (content , "general" )
96+ try :
97+ translated = translator .translate (content , "general" )
98+ except Exception as e :
99+ # Get debug output path if available
100+ debug_info = ""
101+ try :
102+ from src .debug_output import get_debug_manager
103+ debug = get_debug_manager (config )
104+ if debug .enabled and debug .run_dir .exists ():
105+ debug_info = f"\n 📁 Debug outputs: { debug .run_dir } \n Check LLM input/output files for details."
106+ except :
107+ pass
108+
109+ raise RuntimeError (
110+ f"Translation failed with exception: { e } \n "
111+ f" Model: { model } \n "
112+ f" Source: { source_lang } → Target: { target_lang } \n "
113+ f" Input size: { len (content )} chars, { len (content .splitlines ())} lines{ debug_info } \n "
114+ f" Troubleshooting:\n "
115+ f" 1. Verify API key is set correctly (check environment variables)\n "
116+ f" 2. Check API key has sufficient credits/quota\n "
117+ f" 3. Verify model name '{ model } ' is valid and accessible\n "
118+ f" 4. Review debug output files for API response details"
119+ ) from e
97120
98121 # Validate translation result
99122 if not translated :
100- raise ValueError ("Translation returned empty content. Check API key and model configuration." )
123+ # Get debug output path if available
124+ debug_info = ""
125+ try :
126+ from src .debug_output import get_debug_manager
127+ debug = get_debug_manager (config )
128+ if debug .enabled and debug .run_dir .exists ():
129+ debug_info = f"\n 📁 Debug outputs: { debug .run_dir } \n Check 'llm_output_translator_*_translate.md' for API response."
130+ except :
131+ pass
132+
133+ raise ValueError (
134+ f"Translation returned empty content (None).\n "
135+ f" Model: { model } \n "
136+ f" Source: { source_lang } → Target: { target_lang } \n "
137+ f" Input size: { len (content )} chars, { len (content .splitlines ())} lines{ debug_info } \n "
138+ f" Possible causes:\n "
139+ f" 1. API key is missing or invalid\n "
140+ f" 2. API returned empty response (check debug output files)\n "
141+ f" 3. Model '{ model } ' is not available or not responding\n "
142+ f" 4. Network/API connection issue\n "
143+ f" Troubleshooting:\n "
144+ f" - Verify OPENAI_API_KEY environment variable is set\n "
145+ f" - Check API key has sufficient credits\n "
146+ f" - Review debug output files for detailed API response"
147+ )
148+
101149 if len (translated .strip ()) == 0 :
102- raise ValueError ("Translation returned only whitespace. Check API response." )
150+ # Get debug output path if available
151+ debug_info = ""
152+ try :
153+ from src .debug_output import get_debug_manager
154+ debug = get_debug_manager (config )
155+ if debug .enabled and debug .run_dir .exists ():
156+ debug_info = f"\n 📁 Debug outputs: { debug .run_dir } \n Check 'llm_output_translator_*_translate.md' for API response."
157+ except :
158+ pass
159+
160+ raise ValueError (
161+ f"Translation returned only whitespace (empty after stripping).\n "
162+ f" Model: { model } \n "
163+ f" Source: { source_lang } → Target: { target_lang } \n "
164+ f" Input size: { len (content )} chars, { len (content .splitlines ())} lines\n "
165+ f" Raw response length: { len (translated )} chars{ debug_info } \n "
166+ f" Possible causes:\n "
167+ f" 1. API returned whitespace-only response\n "
168+ f" 2. Model generated empty content\n "
169+ f" 3. Response parsing issue\n "
170+ f" Troubleshooting:\n "
171+ f" - Review debug output files to see actual API response\n "
172+ f" - Check if API key has proper permissions\n "
173+ f" - Verify model configuration in config file"
174+ )
103175
104176 print (f" Raw translation: { len (translated )} chars" )
105177
@@ -108,7 +180,31 @@ def translate_file(
108180
109181 # Validate cleaned content
110182 if not translated or len (translated .strip ()) == 0 :
111- raise ValueError ("After cleaning, translation is empty. Check clean_translated_content function." )
183+ # Get debug output path if available
184+ debug_info = ""
185+ try :
186+ from src .debug_output import get_debug_manager
187+ debug = get_debug_manager (config )
188+ if debug .enabled and debug .run_dir .exists ():
189+ debug_info = f"\n 📁 Debug outputs: { debug .run_dir } \n Check 'llm_output_translator_*_translate.md' for original API response."
190+ except :
191+ pass
192+
193+ raise ValueError (
194+ f"After cleaning, translation is empty.\n "
195+ f" Model: { model } \n "
196+ f" Source: { source_lang } → Target: { target_lang } \n "
197+ f" Input size: { len (content )} chars, { len (content .splitlines ())} lines{ debug_info } \n "
198+ f" This suggests the cleaning function (clean_translated_content) removed all content.\n "
199+ f" Possible causes:\n "
200+ f" 1. API response format was unexpected\n "
201+ f" 2. Cleaning function is too aggressive\n "
202+ f" 3. Response contained only artifacts that were removed\n "
203+ f" Troubleshooting:\n "
204+ f" - Review debug output files to see raw API response\n "
205+ f" - Check clean_translated_content function logic\n "
206+ f" - Verify API response format matches expectations"
207+ )
112208
113209 print (f" ✓ Cleaned translation: { len (translated )} chars, { len (translated .splitlines ())} lines" )
114210
0 commit comments