Skip to content

base: fail loudly when extract_locales.js runs outside the repo root - #2123

Open
dajiaohuang wants to merge 1 commit into
armory3d:mainfrom
dajiaohuang:fix/extract-locales-guard
Open

dajiaohuang wants to merge 1 commit into
armory3d:mainfrom
dajiaohuang:fix/extract-locales-guard

Conversation

@dajiaohuang

Copy link
Copy Markdown
Contributor

Fixes #2122.

source_paths and locale_path in base/tools/extract_locales.js are relative to the current working directory, and a missing source path is skipped with continue. Run from anywhere but the repository root, every path is skipped: nothing is extracted, nothing is reported, and the script still exits 0. Since locale_path is relative as well, the output directory normally does not exist at that location, so no file is written either - the command looks like it succeeded.

let found = false;

for (let path of source_paths) {
	if (!fs_exists(path)) {
		continue;
	}
	found = true;
	...
}

if (!found) {
	console.log("No source paths found - run this script from the repository root.");
	std.exit(1);
}

fs_writefile(locale_path, JSON.stringify(out, Object.keys(out).sort(), 4));

This mirrors the existing "Locale code not set!" guard at the top of the same file.

Verification

Scratch tree: paint/sources/demo.c with two tr("...") strings, paint/sources/nodes_material/n.c with one, and an existing paint/assets/locale/zz.json holding a real translation plus a stale key. Driven with the committed base/tools/bin/windows_x64/amake.exe.

Run from paint/:

stdout exit zz.json
before (none) 0 not written
after No source paths found - run this script from the repository root. 1 not written

Run from the repository root - the supported path:

stdout exit generated locale
before (none) 0 3 keys, existing translation preserved
after (none) 0 byte-identical to before

So the correct-cwd behaviour is unchanged; only the silent failure now reports itself. std.exit(1) is used rather than the bare std.exit() at line 11 so the failure is detectable from a script.

Single file, guard only - no extraction or output-format change.

🤖 Generated with Claude Code

The `source_paths` in `base/tools/extract_locales.js` are relative to the
current working directory, and a missing path is skipped with `continue`.
Run from anywhere but the repository root - the readme's own build steps
leave you in `paint/` - every path is skipped, so nothing is extracted,
yet the script exits 0 with no output at all. The relative `locale_path`
means no file is written either, so the command looks like it worked.

Track whether any source path was found and exit non-zero with a message
when none was, matching the existing "Locale code not set!" error path.

Behaviour from the repository root is unchanged: the generated locale is
byte-identical.
@dajiaohuang
dajiaohuang force-pushed the fix/extract-locales-guard branch from ac2f7ee to 4e3fb03 Compare September 11, 2026 10:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

extract_locales.js silently does nothing when run outside the repository root

1 participant