From 8009dfa2d3efe1dc3c8089da2331560fbe47b95b Mon Sep 17 00:00:00 2001 From: Stefano Caldarini Date: Tue, 3 Nov 2026 16:30:50 +0100 Subject: [PATCH] feat: report quota exhaustion as its own quota_exceeded metrics event (1.7.3) A plan running out of characters is not the CLI failing. Commands that stop on an exhausted quota now queue eventType 'quota_exceeded' instead of 'call_error' with errorType 'quota_exceeded', so the error funnel only counts real failures. Metadata is unchanged. --- README.md | 5 +++-- package.json | 2 +- src/__tests__/modules/metrics.test.ts | 17 +++++++++++++++++ src/modules/metrics/metrics.ts | 13 ++++++++----- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index ff8dd63..ba964f8 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Lara Cli automates translation of your i18n files with a single command, preserv Supports multiple file formats including JSON, PO (gettext), TypeScript, Vue I18n single-file components, Markdown and MDX files, Android XML string resource files, Xcode localization files (.strings, .stringsdict, .xcstrings), and plain text (.txt) files. See [Supported Formats](docs/config/formats.md) for details. -[![Version](https://img.shields.io/badge/version-1.7.2-blue.svg)](https://github.com/translated/lara-cli) +[![Version](https://img.shields.io/badge/version-1.7.3-blue.svg)](https://github.com/translated/lara-cli) @@ -231,7 +231,8 @@ because a server can accept a batch even if its response never reaches the CLI. The CLI keeps one pending milestone across commands and remembers it after ingestion acknowledges it. Repeating `init`, translating again or rotating an API key for the same account does not create another milestone. Each command still records its own `call_success` or `call_error`; -`auth_fail` remains a diagnostic event for failed authentication attempts. +`auth_fail` remains a diagnostic event for failed authentication attempts. A command stopped by an +exhausted plan quota records `quota_exceeded` instead of `call_error`. `sessionId` groups commands from the same account on the same machine, including across projects. Each command renews the session; 30 minutes without activity starts a new one. Switching accounts diff --git a/package.json b/package.json index 4ab58f7..06abc9a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@translated/lara-cli", "type": "module", - "version": "1.7.2", + "version": "1.7.3", "description": "CLI tool for automated i18n file translation using Lara Translate", "repository": { "type": "git", diff --git a/src/__tests__/modules/metrics.test.ts b/src/__tests__/modules/metrics.test.ts index 1d78010..9822f37 100644 --- a/src/__tests__/modules/metrics.test.ts +++ b/src/__tests__/modules/metrics.test.ts @@ -953,6 +953,23 @@ describe('finishCommand', () => { expect(typeof queuedEvents()[0]!.latencyMs).toBe('number'); }); + it.each([ + ['directly', [new Error('Your plan quota is exhausted')]], + [ + 'before a generic unwind error', + [new Error('Your plan quota is exhausted'), new Error('Some files could not be translated')], + ], + ])('emits quota_exceeded instead of call_error when quota runs out %s', async (_, errors) => { + const metrics = await loadMetrics(); + metrics.instrument('translate'); + for (const error of errors) metrics.recordError(error); + metrics.finishCommand(1); + + const event = queuedEvents()[0]!; + expect(event).toMatchObject({ eventType: 'quota_exceeded' }); + expect(event).not.toHaveProperty('errorType'); + }); + it.each([ ['text', 'text', { sourceLang: 'en', targetLang: 'pt-br' }], ['file', 'document', { sourceLang: 'en', targetLang: 'pt-br' }], diff --git a/src/modules/metrics/metrics.ts b/src/modules/metrics/metrics.ts index 02540be..748802d 100644 --- a/src/modules/metrics/metrics.ts +++ b/src/modules/metrics/metrics.ts @@ -973,11 +973,14 @@ export function finishCommand(exitCode: number): void { }; if (exitCode !== 0) { - queueEvent({ - eventType: 'call_error', - errorType: errorTypeFor(lastError), - ...common, - }); + // A plan running out of characters is not the CLI failing: it gets its own + // event so the error funnel only counts real failures. + const errorType = errorTypeFor(lastError); + queueEvent( + errorType === 'quota_exceeded' + ? { eventType: 'quota_exceeded', ...common } + : { eventType: 'call_error', errorType, ...common } + ); return; }