Skip to content

Commit debcb6e

Browse files
fix(new-compiler): improve translation error logging (#1991)
Co-authored-by: cherkanov_art <45258907+cherkanovart@users.noreply.github.com>
1 parent 2ed13f3 commit debcb6e

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

.changeset/yellow-cows-hear.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@lingo.dev/compiler": patch
3+
---
4+
5+
Improve translation error logging by writing detailed errors to .lingo/translation-server.log

packages/new-compiler/src/translation-server/translation-server.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ export class TranslationServer {
331331
*/
332332
async translateAll(locale: LocaleCode): Promise<{
333333
translations: Record<string, string>;
334-
errors: Array<{ hash: string; error: string }>;
334+
errors: Array<{ hash: string; sourceText: string; error: string }>;
335335
}> {
336336
if (!this.translationService) {
337337
throw new Error("Translation server not initialized");
@@ -368,6 +368,27 @@ export class TranslationServer {
368368
allHashes,
369369
);
370370

371+
// Log detailed error information to server log file
372+
if (result.errors.length > 0) {
373+
this.logger.error(
374+
`${result.errors.length} translation error(s) for ${locale}:`,
375+
);
376+
for (const err of result.errors) {
377+
const prefix = ` [${locale}]`;
378+
if (err.hash === "all") {
379+
this.logger.error(`${prefix} ${err.error}`);
380+
continue;
381+
}
382+
const source =
383+
err.sourceText.length > 200
384+
? err.sourceText.slice(0, 200) + "..."
385+
: err.sourceText;
386+
this.logger.error(
387+
`${prefix} hash=${err.hash} source="${source}" error="${err.error}"`,
388+
);
389+
}
390+
}
391+
371392
// Broadcast batch complete event
372393
const duration = Date.now() - startTime;
373394
this.broadcast(

packages/new-compiler/src/translators/translation-service.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,14 @@ Set the required API keys for real translations.`);
259259
// Merge translated texts with overridden translations
260260
newTranslations = { ...overriddenTranslations, ...translatedTexts };
261261
} catch (error) {
262-
this.logger.error(`Translation failed:`, error);
262+
const errorMessage =
263+
error instanceof Error ? error.message : String(error);
264+
this.logger.error(
265+
`Translation failed for locale "${locale}": ${errorMessage}`,
266+
);
267+
if (error instanceof Error && error.stack) {
268+
this.logger.debug(`Stack trace: ${error.stack}`);
269+
}
263270

264271
return {
265272
translations: this.pickTranslations(
@@ -270,10 +277,7 @@ Set the required API keys for real translations.`);
270277
{
271278
hash: "all",
272279
sourceText: "all",
273-
error:
274-
error instanceof Error
275-
? error.message
276-
: "Unknown translation error",
280+
error: errorMessage,
277281
},
278282
],
279283
stats: {

0 commit comments

Comments
 (0)