2.7 KiB
traderx_check.py – validate and fix an existing config
Works directly on a TraderX profile folder; independent of the build tool. Useful for configs made with the web editor, by hand, or for a quick health check before start.
python3 traderx_check.py ~/serverprofile/TraderX # report only
python3 traderx_check.py ~/serverprofile/TraderX --decode # + decoded bitfields per product
python3 traderx_check.py ~/serverprofile/TraderX --fix # apply safe fixes (backup first)
python3 traderx_check.py ~/serverprofile/TraderX --fix --fix-settings
The path may be the profiles dir, the TraderX dir or TraderXConfig.
What it reports
Errors (the mod will skip or misread the file):
- file names not matching
prod_<name>_NNN.json/cat_<name>_NNN.json - invalid JSON (line/column), or top-level value not an object
- wrong field types that can't be coerced; missing
className buyPrice/sellPrice/maxStockbelow-1;coefficient ≤ 0- attachments / variants /
productIdspointing at products that don't exist licensesRequiredentries that aren't alicenseIdinTraderXGeneralSettings.json- trader
categoriesIdpointing at missing categories; duplicatenpcId
Warnings:
coefficient ≠ 1with unlimited stock (no effect); very low coefficients- sell > buy; both prices
-1 - unknown mode bits in
tradeQuantity; out-of-rangestockSettings - products not listed in any category (fine for attachments)
- empty categories; traders with no categories
- a
Compiled/folder shadowingProducts/andCategories/
Repeated messages are grouped ((414x) coefficient 0.9 has no effect …); use
--no-group to list them all and --ignore TEXT (repeatable) to mute known-acceptable ones.
What --fix changes
After copying Products/ and Categories/ to Backup_traderx_check_<timestamp>/:
- renames invalid file names (sanitise, append
_001, bump on collision) and rewrites every reference to the old id in categories, attachments, variants and the matchingTraderXDatabase/Stock/<id>.json - adds missing fields with the mod's defaults; coerces
"5"→5,25.0→25; drops unknown keys (e.g. a strayproductIdinside a legacy product file) - removes dangling and duplicate references; converts license names to license ids
--fix-settings: also rewrites renamed category ids intraders[].categoriesId(writesTraderXGeneralSettings.json.bakfirst)
Never changed automatically: invalid JSON, empty class names, prices, stock, coefficients, missing licenses. Run with the server stopped – it renames stock files.
Exit code
0 when no errors remain, 1 otherwise – usable in start scripts (see
scripts/prestart-check.sh).