Skip to content

Commit 8f53c19

Browse files
committed
Improve path validation error message
1 parent c103222 commit 8f53c19

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

scripts/generateTranslations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ async function main(): Promise<void> {
700700
}
701701

702702
if (invalidPaths.length > 0) {
703-
throw new Error(`⚠️ Warning: --paths contains the following invalid paths: ${invalidPaths.join(', ')}`);
703+
throw new Error(`found the following invalid paths: ${JSON.stringify(invalidPaths)}`);
704704
}
705705

706706
return validatedPaths;

tests/unit/generateTranslationsTest.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import dedent from '@libs/StringUtils/dedent';
99
import generateTranslations, {GENERATED_FILE_PREFIX} from '@scripts/generateTranslations';
1010
import Translator from '@scripts/utils/Translator/Translator';
1111

12-
let mockExit: jest.SpyInstance;
12+
let processExitSpy: jest.SpyInstance;
13+
let consoleErrorSpy: jest.SpyInstance;
1314

1415
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment
1516
let mockEn: any = jest.requireActual('@src/languages/en');
@@ -33,7 +34,8 @@ describe('generateTranslations', () => {
3334
const ORIGINAL_ARGV = process.argv;
3435

3536
beforeEach(() => {
36-
mockExit = jest.spyOn(process, 'exit').mockImplementation(() => undefined as never);
37+
processExitSpy = jest.spyOn(process, 'exit').mockImplementation(() => undefined as never);
38+
consoleErrorSpy = jest.spyOn(console, 'error');
3739

3840
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'translations-test-'));
3941
LANGUAGES_DIR = path.join(tempDir, 'src/languages');
@@ -730,8 +732,9 @@ describe('generateTranslations', () => {
730732
process.argv = ['ts-node', 'generateTranslations.ts', '--dry-run', '--verbose', '--locales', 'it', '--paths', 'nonexistent.path'];
731733

732734
// Expect the script to throw an error during CLI parsing
733-
await expect(generateTranslations()).rejects.toThrow('Translation path not found: nonexistent.path');
734-
expect(mockExit).toHaveBeenCalledWith(1);
735+
await generateTranslations();
736+
expect(consoleErrorSpy).toHaveBeenCalledWith('Invalid value for --paths: found the following invalid paths: ["nonexistent.path"]');
737+
expect(processExitSpy).toHaveBeenCalledWith(1);
735738
});
736739

737740
it('validates paths against actual translation structure', async () => {

0 commit comments

Comments
 (0)