Skip to content
Snippets Groups Projects
Verified Commit ba4bf297 authored by Sven Kirschbaum's avatar Sven Kirschbaum
Browse files

fix: Provide more specific error message if the xml can not be parsed

parent 408937d2
No related branches found
No related tags found
No related merge requests found
...@@ -13,12 +13,20 @@ class StackQuestionLoader ...@@ -13,12 +13,20 @@ class StackQuestionLoader
{ {
static public function loadXML($xml) { static public function loadXML($xml) {
//TODO: Consider defaults //TODO: Consider defaults
try {
$xmlData = new SimpleXMLElement($xml); $xmlData = new SimpleXMLElement($xml);
} catch (\Exception $e) {
throw new \stack_exception("The provided file does not contain valid XML");
}
$question = new \qtype_stack_question(); $question = new \qtype_stack_question();
//Throw error if more then one question element is contained in the xml //Throw error if more then one question element is contained in the xml
if (count($xmlData->question) != 1) { if (count($xmlData->question) != 1) {
throw new \stack_exception("The provided xml file contains more than one question element"); throw new \stack_exception("The provided XML file does not contain exactly one question element");
}
if (((string) $xmlData->question->attributes()->type) !== "stack") {
throw new \stack_exception("The provided question is not of type STACK");
} }
//Collect included files //Collect included files
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment