Skip to content

Commit

Permalink
scripts: west_commands: add JSON excepthook
Browse files Browse the repository at this point in the history
To be used with west commands implementing a jsonschema based protocol.

Signed-off-by: Gerard Marull-Paretas <[email protected]>
  • Loading branch information
gmarull committed Jan 2, 2025
1 parent 2a97534 commit 468f3b3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,7 @@
/scripts/ncs-toolchain-version-minimum.txt @nrfconnect/ncs-co-build-system @nrfconnect/ncs-ci
/scripts/tools-versions-*.txt @nrfconnect/ncs-co-build-system @nrfconnect/ncs-ci
/scripts/requirements-*.txt @nrfconnect/ncs-co-build-system @nrfconnect/ncs-ci
/scripts/west_commands/utils/ @gmarull
/scripts/west_commands/create_board/ @gmarull
/scripts/west_commands/ncs-bicr.py @gmarull
/scripts/west_commands/ncs-board-actions.py @gmarull
Expand Down
24 changes: 24 additions & 0 deletions scripts/west_commands/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (c) 2024 Nordic Semiconductor ASA
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause

import json
import sys
import traceback


def install_json_excepthook():
def excepthook(type, value, tb):
output = {
"errors": [
{
"type": type.__name__,
"message": str(value),
"traceback": "".join(traceback.format_tb(tb))
}
]
}

print(json.dumps(output, indent=2), file=sys.stderr)
sys.exit(1)

sys.excepthook = excepthook

0 comments on commit 468f3b3

Please sign in to comment.