Skip to content

Commit

Permalink
MDL-68971 webservice: errors should give enough info to find the problem
Browse files Browse the repository at this point in the history
  • Loading branch information
timhunt authored and junpataleta committed Jun 17, 2020
1 parent 7532b03 commit 6a7042d
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions lib/externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,12 @@ public static function external_function_info($function, $strictness=MUST_EXIST)
$function->classpath = $CFG->dirroot.'/'.$function->classpath;
}
if (!file_exists($function->classpath)) {
throw new coding_exception('Cannot find file with external function implementation');
throw new coding_exception('Cannot find file ' . $function->classpath .
' with external function implementation');
}
require_once($function->classpath);
if (!class_exists($function->classname)) {
throw new coding_exception('Cannot find external class');
throw new coding_exception('Cannot find external class ' . $function->classname);
}
}

Expand All @@ -99,13 +100,16 @@ public static function external_function_info($function, $strictness=MUST_EXIST)

// Make sure the implementaion class is ok.
if (!method_exists($function->classname, $function->methodname)) {
throw new coding_exception('Missing implementation method of '.$function->classname.'::'.$function->methodname);
throw new coding_exception('Missing implementation method ' .
$function->classname . '::' . $function->methodname);
}
if (!method_exists($function->classname, $function->parameters_method)) {
throw new coding_exception('Missing parameters description');
throw new coding_exception('Missing parameters description method ' .
$function->classname . '::' . $function->parameters_method);
}
if (!method_exists($function->classname, $function->returns_method)) {
throw new coding_exception('Missing returned values description');
throw new coding_exception('Missing returned values description method ' .
$function->classname . '::' . $function->returns_method);
}
if (method_exists($function->classname, $function->deprecated_method)) {
if (call_user_func(array($function->classname, $function->deprecated_method)) === true) {
Expand All @@ -117,14 +121,16 @@ public static function external_function_info($function, $strictness=MUST_EXIST)
// Fetch the parameters description.
$function->parameters_desc = call_user_func(array($function->classname, $function->parameters_method));
if (!($function->parameters_desc instanceof external_function_parameters)) {
throw new coding_exception('Invalid parameters description');
throw new coding_exception($function->classname . '::' . $function->parameters_method .
' did not return a valid external_function_parameters object.');
}

// Fetch the return values description.
$function->returns_desc = call_user_func(array($function->classname, $function->returns_method));
// Null means void result or result is ignored.
if (!is_null($function->returns_desc) and !($function->returns_desc instanceof external_description)) {
throw new coding_exception('Invalid return description');
throw new coding_exception($function->classname . '::' . $function->returns_method .
' did not return a valid external_description object');
}

// Now get the function description.
Expand Down

0 comments on commit 6a7042d

Please sign in to comment.