From 00f7ed380b90cc003c3f99a6ce116b885a7469ec Mon Sep 17 00:00:00 2001 From: John Denker Date: Wed, 10 Nov 2021 15:05:27 -0700 Subject: display more-informative error message; required stripping off two layers of concealment --- displayformula.php | 9 ++++----- lang/en/qtype_algebra.php | 6 ++++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/displayformula.php b/displayformula.php index 6ba12fb..9890ea5 100644 --- a/displayformula.php +++ b/displayformula.php @@ -34,7 +34,7 @@ global $PAGE, $CFG; require_login(); $p = new qtype_algebra_parser; -$validanswer = true; +$errmsg = ''; try { $query = urldecode($_SERVER['QUERY_STRING']); @@ -66,16 +66,15 @@ try { } } catch (Exception $e) { - $validanswer = false; - $texexp = get_string('parseerror', 'qtype_algebra', $e->getMessage()); + $errmsg = $e->getMessage(); } $formatoptions = new stdClass; $formatoptions->para = false; $PAGE->set_context(context_system::instance()); -if ($validanswer) { +if ($errmsg == '') { $text = format_text($texexp, FORMAT_MOODLE, $formatoptions); } else { - $text = get_string('invalidanswer', 'qtype_algebra'); + $text = get_string('trivial_1', 'qtype_algebra', $errmsg); } ?> diff --git a/lang/en/qtype_algebra.php b/lang/en/qtype_algebra.php index 81baad5..b29682e 100644 --- a/lang/en/qtype_algebra.php +++ b/lang/en/qtype_algebra.php @@ -23,6 +23,8 @@ */ // Parser lang strings. +$string['deprecatedlog'] = 'log() is deprecated; use ln() or log10() instead'; +$string['trivial_1'] = '{$a}'; $string['badclosebracket'] = 'Invalid close bracket found'; $string['badequivtype'] = 'Invalid type: can only compare parser terms with other parser terms'; $string['badfuncargs'] = 'Invalid arguments for the function \'{$a}\''; @@ -111,7 +113,7 @@ $string['notenoughvars'] = 'You must enter at least one variable.'; $string['novarmax'] = 'No maximum bound specified for variable.'; $string['novarmin'] = 'No minimum bound specified for variable.'; $string['options'] = 'Options'; -$string['parseerror'] = 'Error parsing function: \'{$a}\''; +$string['parseerror'] = 'Error parsing function: \'{$a}\''; /* not used at the moment */ $string['restoreqdbfailed'] = 'Restoring algebra question failed: database write error'; $string['restorevardbfailed'] = 'Restoring algebra question variable failed: database write error'; $string['tolerance'] = 'Tolerance for Evaluation Checks'; @@ -146,7 +148,7 @@ $string['dollars'] = '$$...$$'; $string['brackets'] = '\[...\]'; $string['braces'] = '\\(...\\)'; $string['dollar'] = '$...$'; -$string['invalidanswer'] = 'Invalid or unrecongnized answer'; +$string['invalidanswer'] = 'Invalid or unrecognized answer:
{$a}'; /* not used at the moment */ $string['multiplyoperator'] = 'TeX operator for multiplication'; $string['times'] = '\\times'; $string['cdot'] = '\\cdot'; -- cgit v1.2.3