{"record":{"id":"6702f83573e4acfb","repo":"moodle/moodle","slug":"bad-slot-id","errorCode":null,"errorMessage":"Bad slot ID ","messagePattern":"Bad slot ID ","errorType":"exception","errorClass":"moodle_exception","httpStatus":null,"severity":"error","filePath":"public/mod/quiz/classes/structure.php","lineNumber":854,"sourceCode":"\n    /**\n     * Move a slot from its current location to a new location.\n     *\n     * After calling this method, this class will be in an invalid state, and\n     * should be discarded if you want to manipulate the structure further.\n     *\n     * @param int $idmove id of slot to be moved\n     * @param int $idmoveafter id of slot to come before slot being moved\n     * @param int $page new page number of slot being moved\n     */\n    public function move_slot($idmove, $idmoveafter, $page) {\n        global $DB;\n\n        $this->check_can_be_edited();\n\n        $movingslot = $this->get_slot_by_id($idmove);\n        if (empty($movingslot)) {\n            throw new \\moodle_exception('Bad slot ID ' . $idmove);\n        }\n        $movingslotnumber = (int) $movingslot->slot;\n\n        // Empty target slot means move slot to first.\n        if (empty($idmoveafter)) {\n            $moveafterslotnumber = 0;\n        } else {\n            $moveafterslotnumber = (int) $this->get_slot_by_id($idmoveafter)->slot;\n        }\n\n        // If the action came in as moving a slot to itself, normalise this to\n        // moving the slot to after the previous slot.\n        if ($moveafterslotnumber == $movingslotnumber) {\n            $moveafterslotnumber = $moveafterslotnumber - 1;\n        }\n\n        $followingslotnumber = $moveafterslotnumber + 1;\n        // Prevent checking against non-existence slot when already at the last slot.","sourceCodeStart":836,"sourceCodeEnd":872,"githubUrl":"https://github.com/moodle/moodle/blob/48ea8c33227277e916cdd4079dbecef448b37f2c/public/mod/quiz/classes/structure.php#L836-L872","documentation":"Thrown by structure::move_slot() when the id of the slot to move ($idmove) does not correspond to any slot record in this quiz — get_slot_by_id() returns empty. Uses \\moodle_exception with a raw message 'Bad slot ID <id>' rather than a language string.","triggerScenarios":"Calling move_slot() with a slot id that does not exist, belongs to a different quiz, or was already deleted; passing an invalid/garbage id from client JS.","commonSituations":"Stale page data after another user restructured the quiz; AJAX sends an outdated slot id; ids mixed up between quizzes; copy-paste of a slotcord id from the wrong quiz id.","solutions":["Verify the slot id belongs to the current quiz (query quiz_slots by id and check the quizid).","Reload the quiz edit page / re-fetch the structure to get fresh slot ids before moving.","Correct the id passed to move_slot(); ensure it comes from get_slot_by_id()/structure listing for this quiz.","If concurrent edits are common, re-fetch and retry, or handle empty lookups gracefully before calling."],"exampleFix":"// before\n$structure->move_slot($slotid, $moveafter); // $slotid from stale UI\n// after\n$slot = $structure->get_slot_by_id($slotid);\nif (!empty($slot)) {\n    $structure->move_slot($slotid, $moveafter);\n}","handlingStrategy":"validation","validationCode":"$slot = $structure->get_slot_by_id($slotid);\nif (empty($slot)) { // abort or refetch structure before moving\n}","typeGuard":null,"tryCatchPattern":"try {\n    $structure->move_slot($slotid, $moveafter);\n} catch (\\moodle_exception $e) {\n    if (str_starts_with($e->getMessage(), 'Bad slot ID')) {\n        // reload structure and retry with fresh ids\n    }\n}","preventionTips":["Always derive slot ids from a fresh structure fetch","Re-fetch after concurrent edits by other users","Validate the slot's quizid matches the current quiz before moving"],"tags":["moodle","quiz","slots","not-found"],"backgroundTag":"record-not-found","analyzedSha":"48ea8c33227277e916cdd4079dbecef448b37f2c","analyzedAt":"2026-09-14T20:34:48.527Z","contentChangedAt":"2026-09-14T20:34:48.527Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}