fix(cli): don't crash tos.py monitor/flash on an unbuilt project - #690
Open
maidang-xing wants to merge 1 commit into
Open
fix(cli): don't crash tos.py monitor/flash on an unbuilt project#690maidang-xing wants to merge 1 commit into
maidang-xing wants to merge 1 commit into
Conversation
`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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
tos.py monitorandtos.py flashreadusing.configvia plain dict-subscript (using_data["CONFIG_PLATFORM_CHOICE"], etc.). When the project has never been built,using.configdoesn't exist yet,parse_config_file()silently returns{}, and the subscript throws an unhandledKeyError(raw Python traceback) instead of a usable message.monitornow callsinit_using_config(force=False)before reading the config (same callbuildalready makes), so the correct per-board baudrate is derived fromapp_default.configeven without a prior build.flashgets the sameinit_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 forCONFIG_PLATFORM_CHOICEinget_flash_cmd()— the one remaining spot that could stillKeyError(e.g. a hand-edited/corruptedusing.config).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 monitoron an unbuilt project (nousing.config) now derives the correct board baudrate instead of crashing withKeyError: 'CONFIG_PLATFORM_CHOICE'tos.py flashon an unbuilt project (nousing.config, no bin) now printsNot found bin file, please use [tos.py build].instead of crashingtos.py flashwithusing.configpresent but missingCONFIG_PLATFORM_CHOICEnow printsNot found platform, please use [tos.py config].instead of crashingtos.py flashwhere onlyusing.configwas 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