From 82dd881b29f573e8f0ed9baabb05ccd543418ce7 Mon Sep 17 00:00:00 2001 From: "Jessica B. Hamrick" Date: Thu, 23 Jun 2022 11:14:39 +0100 Subject: [PATCH] More informative error messages in ClearSolutions --- nbgrader/preprocessors/clearsolutions.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/nbgrader/preprocessors/clearsolutions.py b/nbgrader/preprocessors/clearsolutions.py index 390f891fe..03ab3c13f 100644 --- a/nbgrader/preprocessors/clearsolutions.py +++ b/nbgrader/preprocessors/clearsolutions.py @@ -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") @@ -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 @@ -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) @@ -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."