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

More informative error messages in ClearSolutions #1607

Merged
merged 1 commit into from
Jun 23, 2022
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
7 changes: 7 additions & 0 deletions nbgrader/preprocessors/clearsolutions.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def _replace_solution_region(self, cell: NotebookNode, language: str) -> bool:
# check to make sure this isn't a nested BEGIN
# SOLUTION region
if in_solution:
self.log.error("Encountered nested begin solution statements. Cell contents are: \n%s", cell.source)
raise RuntimeError(
"encountered nested begin solution statements")

Expand All @@ -120,6 +121,7 @@ def _replace_solution_region(self, cell: NotebookNode, language: str) -> bool:
# we finished going through all the lines, but didn't find a
# matching END SOLUTION statment
if in_solution:
self.log.error("No end solution statement found. Cell contents are: \n%s", cell.source)
raise RuntimeError("no end solution statement found")

# replace the cell source
Expand All @@ -146,6 +148,7 @@ def preprocess_cell(self,
cell_index: int
) -> Tuple[NotebookNode, ResourcesDict]:
# replace solution regions with the relevant stubs
orig_cell_source = cell.source
language = resources["language"]
replaced_solution = self._replace_solution_region(cell, language)

Expand All @@ -157,6 +160,10 @@ def preprocess_cell(self,
# to be given an id
if not is_solution and replaced_solution:
if self.enforce_metadata:
self.log.error(
"Solution region detected in a non-solution cell; please make sure "
"all solution regions are within solution cells. Cell contents are: \n%s", orig_cell_source
)
raise RuntimeError(
"Solution region detected in a non-solution cell; please make sure "
"all solution regions are within solution cells."
Expand Down