Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error log to json in run_sorter #3057

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/spikeinterface/sorters/basesorter.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,12 @@ def run_from_folder(cls, output_folder, raise_error, verbose):
has_error = True
run_time = None
log["error"] = True
log["error_trace"] = traceback.format_exc()
error_log_to_display = traceback.format_exc()
trace_lines = error_log_to_display.strip().split("\n")
error_to_json = ["Traceback (most recent call last):"] + [
f" {line}" if not line.startswith(" ") else line for line in trace_lines[1:]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the space before {line} needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. Removing it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh no sorry I understand maybe it was to keep the left-alignment the same for lines that already start with a space vs. dont? In that case can leave, or maybe just .strip() all lines?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel it does not matter that much? The big gain is dividing the error trace in lines so it does not appear like a super-long-line in json I feel.

]
log["error_trace"] = error_to_json

log["error"] = has_error
log["run_time"] = run_time
Expand Down Expand Up @@ -290,7 +295,7 @@ def run_from_folder(cls, output_folder, raise_error, verbose):

if has_error and raise_error:
raise SpikeSortingError(
f"Spike sorting error trace:\n{log['error_trace']}\n"
f"Spike sorting error trace:\n{error_log_to_display}\n"
f"Spike sorting failed. You can inspect the runtime trace in {output_folder}/spikeinterface_log.json."
)

Expand Down