Skip to content

Commit

Permalink
pybricksdev.cli.lwp3.repl: better handling of SyntaxError
Browse files Browse the repository at this point in the history
This changes the output on a SyntaxError to only show the relevant info
instead of the full stack trace.
  • Loading branch information
dlech committed Jul 1, 2024
1 parent 777ee0f commit 1c779f5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed
- Improved `SyntaxError` handling in `lwp3 repl` command.

### Fixed
- Fixed `PortID` exception when running `lwp3 repl` command.

Expand Down
9 changes: 8 additions & 1 deletion pybricksdev/cli/lwp3/repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,15 @@ async def welcome():
msg = eval(result, _eval_pool)
if not isinstance(msg, AbstractMessage):
raise ValueError("not a message object")
except SyntaxError as ex:
logger.error(
"%s\n\n %s\n %s",
ex.msg,
ex.text,
" " * ex.offset + "^" * (ex.end_offset - ex.offset),
)
except Exception:
logger.exception("bad input:")
logger.exception("unexpected error:")
else:
logger.info("sending: %s", msg)
await client.write_gatt_char(
Expand Down

0 comments on commit 1c779f5

Please sign in to comment.