-
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 14 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,60 @@ def _run_convert_nwb_dataset( | |
|
|
||
| converter = convert_nwb_dataset(nwb_paths=handled_nwb_paths, run_config=run_config) | ||
|
|
||
| if silent: | ||
| return | ||
|
|
||
| notifications = converter.messages | ||
| 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] | ||
|
|
||
| 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.' | ||
| ) | ||
| console_notification += rich_click.style(text=notification_text, fg="yellow") | ||
| if errors: | ||
| number_of_errors = len(errors) | ||
|
|
||
| top_three = errors[:3] | ||
| number_to_print = len(top_three) | ||
|
|
||
| if console_notification != "" and not silent: | ||
| 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" | ||
| ) | ||
| if number_to_print > 1 and number_of_errors > 3: | ||
| error_text = "".join(f"\n\t- {error.reason}" for error in top_three) | ||
| text += ( | ||
| f"The first {number_to_print} of {number_of_errors} are shown below:\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=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 | ||
|
Comment on lines
126
to
161
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. These two if statements seem to assume that If no such assumption is made, the intent of the block of code is to ignore any elements in
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. It's an order of precedence If any errors, those and only those take priority as information back to the user If not any errors but some critical, those are then displayed in a less scary manner Overall trying to limit the amount of output the CLI can flood in these events All notifications will be included in the linked log dump, so if user checks that they will know all |
||
|
|
||
| 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" | ||
| ) | ||
| text += "\n\n" | ||
| console_notification += rich_click.style(text=text, 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 |
|---|---|---|
|
|
@@ -35,15 +35,15 @@ class BidsSessionMetadata(BaseMetadataContainerModel): | |
| @property | ||
| def messages(self) -> list[InspectionResult]: | ||
| messages = self.participant.messages.copy() | ||
| messages += self._internal_messages | ||
| messages += self._internal_messages.copy() | ||
| if self.events is not None: | ||
| messages += self.events.messages | ||
| messages += self.events.messages.copy() | ||
| if self.probe_table is not None: | ||
| messages += self.probe_table.messages | ||
| messages += self.probe_table.messages.copy() | ||
| if self.channel_table is not None: | ||
| messages += self.channel_table.messages | ||
| messages += self.channel_table.messages.copy() | ||
| if self.electrode_table is not None: | ||
| messages += self.electrode_table.messages | ||
| messages += self.electrode_table.messages.copy() | ||
|
||
| messages.sort(key=lambda message: (-message.category.value, -message.severity.value, message.title)) | ||
| return messages | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.