diff --git a/blog/lib.php b/blog/lib.php index 1cd66666f553..0d4bb4ed8bf6 100644 --- a/blog/lib.php +++ b/blog/lib.php @@ -1220,7 +1220,7 @@ function blog_validate_access($courseid, $modid, $groupid, $entryid, $userid) { throw new \moodle_exception('courseblogdisable', 'blog'); } if (!$mod = $DB->get_record('course_modules', array('id' => $modid))) { - throw new \moodle_exception('invalidmoduleid', 'error', $modid); + throw new \moodle_exception('invalidmoduleid', 'error', '', $modid); } $courseid = $mod->course; } diff --git a/completion/tests/generator/lib.php b/completion/tests/generator/lib.php index 2b6617044033..71c1d0ec7cd1 100644 --- a/completion/tests/generator/lib.php +++ b/completion/tests/generator/lib.php @@ -45,7 +45,7 @@ public function create_default_completion($record): stdClass { throw new moodle_exception('modulerequired'); } if (!$DB->get_record('modules', ['id' => $record['module']])) { - throw new moodle_exception('invalidmoduleid'); + throw new moodle_exception('invalidmoduleid', 'error', '', $record['module']); } $record = (object) array_merge([ diff --git a/lib/modinfolib.php b/lib/modinfolib.php index 4e1201aaa851..7f0356b4b364 100644 --- a/lib/modinfolib.php +++ b/lib/modinfolib.php @@ -2848,7 +2848,7 @@ function get_course_and_cm_from_instance($instanceorid, $modulename, $courseorid $modinfo = get_fast_modinfo($course, $userid); $instances = $modinfo->get_instances_of($modulename); if (!array_key_exists($instanceid, $instances)) { - throw new moodle_exception('invalidmoduleid', 'error', $instanceid); + throw new moodle_exception('invalidmoduleid', 'error', '', $instanceid); } return array($course, $instances[$instanceid]); } diff --git a/lib/tests/modinfolib_test.php b/lib/tests/modinfolib_test.php index af0121132af8..462663983e3c 100644 --- a/lib/tests/modinfolib_test.php +++ b/lib/tests/modinfolib_test.php @@ -1001,6 +1001,14 @@ public function test_get_course_and_cm_from_instance() { $this->assertInstanceOf('dml_exception', $e); } + // Invalid module ID. + try { + get_course_and_cm_from_instance(-1, 'page', $course); + $this->fail(); + } catch (moodle_exception $e) { + $this->assertStringContainsString('Invalid module ID: -1', $e->getMessage()); + } + // Invalid module name. try { get_course_and_cm_from_cmid($page->cmid, '1337 h4x0ring');