-
Notifications
You must be signed in to change notification settings - Fork 4
Enhance error notifications #193
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
Changes from all commits
1aaad89
0a25661
d504162
637d083
8272663
f338a98
7097c60
f1bea9c
6487279
7c4dde6
69f0c74
2edc49c
ee88e92
fb34d6a
25a5230
82f4876
1f46a75
7c42b6b
6d3b066
e95399d
1fec0f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,12 @@ | ||
| import collections | ||
| import pathlib | ||
| import typing | ||
|
|
||
| import rich_click | ||
|
|
||
| from .._converters._run_config import RunConfig | ||
| from .._core._convert_nwb_dataset import convert_nwb_dataset | ||
| from .._inspection._inspection_result import Severity | ||
| from .._inspection._inspection_result import InspectionResult, Severity | ||
| from .._tools._pluralize import _pluralize | ||
| from ..testing import generate_ephys_tutorial | ||
|
|
||
|
|
@@ -112,23 +113,64 @@ def _run_convert_nwb_dataset( | |
|
|
||
| converter = convert_nwb_dataset(nwb_paths=handled_nwb_paths, run_config=run_config) | ||
|
|
||
| if silent: | ||
| return | ||
|
|
||
| notifications = converter.messages | ||
| console_notification = "" | ||
| if notifications: | ||
| notification_text = ( | ||
| f'\n{(n:=len(notifications))} {_pluralize(n=n, word="suggestion")} for improvement ' | ||
| f'{_pluralize(n=n, word="was", plural="were")} found during conversion.' | ||
| notifications_by_severity: dict[Severity, list[InspectionResult]] = collections.defaultdict(list) | ||
| for notification in notifications: | ||
| notifications_by_severity[notification.severity].append(notification) | ||
| errors = notifications_by_severity[Severity.ERROR] | ||
| criticals = notifications_by_severity[Severity.CRITICAL] | ||
|
|
||
| if errors: | ||
| number_of_errors = len(errors) | ||
|
|
||
| top_three = errors[:3] | ||
| number_to_print = len(top_three) | ||
|
|
||
| text = ( | ||
| "\nBIDS dataset was not successfully created!\n" | ||
| f'{_pluralize(n=number_to_print, phrase="An error was", plural="Some errors were")} ' | ||
| "encountered during conversion.\n" | ||
| ) | ||
| error_text = "".join(f"\n\t- {error.reason}" for error in top_three) | ||
| if number_to_print > 1 and number_of_errors > 3: | ||
| counting_text = f"The first {number_to_print} of {number_of_errors} are shown below:" | ||
| elif number_to_print >= 2: | ||
| counting_text = f"The first {number_to_print} are shown below:" | ||
| else: | ||
| counting_text = "The error is shown below:" | ||
| text += ( | ||
| f"{counting_text}\n\n" | ||
| f"{error_text}\n\n" | ||
| # TODO: "The full log file can be found at {run_config.log_file_path}\n" | ||
| ) | ||
| console_notification += rich_click.style(text=notification_text, fg="yellow") | ||
|
|
||
| if console_notification != "" and not silent: | ||
| console_notification = rich_click.style(text=text, fg="red") | ||
| rich_click.echo(message=console_notification) | ||
| return | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you return here, what if the
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Errors take priority over criticals. Both will show up in the full logs (next PR) |
||
|
|
||
| not_any_failures = not any(notification.severity == Severity.ERROR for notification in notifications) | ||
| if not_any_failures and not silent: | ||
| text = "\nBIDS dataset was successfully created!\n\n" | ||
| console_notification = rich_click.style(text=text, fg="green") | ||
| if criticals: | ||
| text = ( | ||
| "\nBIDS dataset was successfully created, but may not be valid!\n" | ||
| # TODO: "Please review the full notifications report at {run_config.log_file_path}\n\n" | ||
| ) | ||
| console_notification = rich_click.style(text=text, fg="yellow") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The color coding seems a bit unconventional here. The why coding a message related to critical issues in yellow while coding a message related to error issues in red in line 145.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'yellow' akin to 'warning' 'red' akin to breaking 'error'
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tend to think critical as more severe than error.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the naming convention needs a revamp for clarity |
||
| rich_click.echo(message=console_notification) | ||
| return | ||
|
|
||
| text = "\nBIDS dataset was successfully created!" | ||
| if notifications: | ||
CodyCBakerPhD marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| number_of_notifications = len(notifications) | ||
|
|
||
| text += ( | ||
| f'\n{number_of_notifications} {_pluralize(n=number_of_notifications, phrase="suggestion")} for improvement ' | ||
| f'{_pluralize(n=number_of_notifications, phrase="was", plural="were")} found during conversion.' | ||
| # TODO: " Please review the full notifications report at {run_config.log_file_path}\n" | ||
| ) | ||
| console_notification = rich_click.style(text=text + "\n\n", fg="green") | ||
| rich_click.echo(message=console_notification) | ||
|
|
||
|
|
||
| # nwb2bids tutorial | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| def _pluralize(n: int, word: str, plural: str | None = None) -> str: | ||
| def _pluralize(n: int, phrase: str, plural: str | None = None) -> str: | ||
| if n == 1: | ||
| return word | ||
| return phrase | ||
| elif plural is None: | ||
| return word + "s" | ||
| return phrase + "s" | ||
| else: | ||
| return plural |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -122,8 +122,8 @@ def test_remote_convert_nwb_dataset_on_gotten_datalad_file( | |
| # TODO: in follow-up, fix the bug preventing electrodes and probes files from being created | ||
| # "sub-fCamk1_ses-fCamk1_200827_sess9_no_raw_data_electrodes.json", | ||
| # "sub-fCamk1_ses-fCamk1_200827_sess9_no_raw_data_electrodes.tsv", | ||
| # "sub-fCamk1_ses-fCamk1_200827_sess9_no_raw_data_probes.json", | ||
| # "sub-fCamk1_ses-fCamk1_200827_sess9_no_raw_data_probes.tsv", | ||
| "sub-fCamk1_ses-fCamk1_200827_sess9_no_raw_data_probes.json", | ||
| "sub-fCamk1_ses-fCamk1_200827_sess9_no_raw_data_probes.tsv", | ||
|
Comment on lines
+125
to
+126
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😜 That's fun - while debugging the new test case for this PR also fixed a separate issue about faulty skipping of probe metadata |
||
| "sub-fCamk1_ses-fCamk1_200827_sess9_no_raw_data_events.json", | ||
| "sub-fCamk1_ses-fCamk1_200827_sess9_no_raw_data_events.tsv", | ||
| }, | ||
|
|
@@ -182,8 +182,8 @@ def test_remote_convert_nwb_dataset_on_partial_datalad_dataset( | |
| # TODO: in follow-up, fix the bug preventing electrodes and probes files from being created | ||
| # "sub-fCamk1_ses-fCamk1_200827_sess9_no_raw_data_electrodes.json", | ||
| # "sub-fCamk1_ses-fCamk1_200827_sess9_no_raw_data_electrodes.tsv", | ||
| # "sub-fCamk1_ses-fCamk1_200827_sess9_no_raw_data_probes.json", | ||
| # "sub-fCamk1_ses-fCamk1_200827_sess9_no_raw_data_probes.tsv", | ||
| "sub-fCamk1_ses-fCamk1_200827_sess9_no_raw_data_probes.json", | ||
| "sub-fCamk1_ses-fCamk1_200827_sess9_no_raw_data_probes.tsv", | ||
| "sub-fCamk1_ses-fCamk1_200827_sess9_no_raw_data_events.json", | ||
| "sub-fCamk1_ses-fCamk1_200827_sess9_no_raw_data_events.tsv", | ||
| }, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.