Skip to content

fix(cli): don't crash tos.py monitor/flash on an unbuilt project - #690

Open
maidang-xing wants to merge 1 commit into
tuya:masterfrom
maidang-xing:fix/tos-monitor-flash-unbuilt-project
Open

fix(cli): don't crash tos.py monitor/flash on an unbuilt project#690
maidang-xing wants to merge 1 commit into
tuya:masterfrom
maidang-xing:fix/tos-monitor-flash-unbuilt-project

Conversation

@maidang-xing

Copy link
Copy Markdown
Contributor

Summary

  • tos.py monitor and tos.py flash read using.config via plain dict-subscript (using_data["CONFIG_PLATFORM_CHOICE"], etc.). When the project has never been built, using.config doesn't exist yet, parse_config_file() silently returns {}, and the subscript throws an unhandled KeyError (raw Python traceback) instead of a usable message.
  • monitor now calls init_using_config(force=False) before reading the config (same call build already makes), so the correct per-board baudrate is derived from app_default.config even without a prior build.
  • flash gets the same init_using_config() call, so an unbuilt project now hits the existing "Not found bin file, please use [tos.py build]." message instead of crashing. Also added a friendly guard + .get() fallback for CONFIG_PLATFORM_CHOICE in get_flash_cmd() — the one remaining spot that could still KeyError (e.g. a hand-edited/corrupted using.config).
  • Hardened get_configure_baudrate() / check_bin_file() to use .get() with graceful fallback instead of hard subscripting, since they're shared helpers reachable from more than one call site.

Test plan

  • tos.py monitor on an unbuilt project (no using.config) now derives the correct board baudrate instead of crashing with KeyError: 'CONFIG_PLATFORM_CHOICE'
  • tos.py flash on an unbuilt project (no using.config, no bin) now prints Not found bin file, please use [tos.py build]. instead of crashing
  • tos.py flash with using.config present but missing CONFIG_PLATFORM_CHOICE now prints Not found platform, please use [tos.py config]. instead of crashing
  • tos.py flash where only using.config was regenerated but the bin file still exists successfully proceeds to the flash step (self-heals)
  • python3 -c "import ast; ast.parse(...)" syntax check on both changed files

🤖 Generated with Claude Code

`monitor` and `flash` both read using.config via a plain dict-subscript
(using_data["CONFIG_PLATFORM_CHOICE"], etc.). When the project has never
been built, using.config doesn't exist yet, parse_config_file() silently
returns {}, and the subscript throws an unhandled KeyError instead of a
usable error message.

- monitor: derive using.config from app_default.config via
  init_using_config(force=False) before reading it (same call `build`
  already makes), so the correct per-board baudrate is picked up even
  without a prior build.
- flash: same init_using_config() call so an unbuilt project now hits
  the existing "Not found bin file, please use [tos.py build]." message
  instead of crashing; also add a friendly guard + .get() fallback for
  CONFIG_PLATFORM_CHOICE in get_flash_cmd(), the one remaining spot that
  could still KeyError (e.g. a hand-edited/corrupted using.config).
- harden get_configure_baudrate()/check_bin_file() to use .get() with
  graceful fallback instead of hard subscripting, since they're shared
  helpers other call sites can reach without going through the same
  guards.
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.

1 participant