-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide a usefull error when ask*() is not used wihtin a task() #1083
Conversation
This small new function can obviously be used in more places but I thought this would be a good start. |
Cool. i think this is helpful. |
Please update changelog. |
done. |
src/functions.php
Outdated
* This method provides a usefull error to the end-user to make him/her aware | ||
* to use a function in the required task-context. | ||
*/ | ||
function requiresTaskContext($callerName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think better to create method in Context
:
Context::required();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also thought about that option. will change it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now I know again why I decided against a method in Context ;-):
the message and logic here is rather task specific and Context
class atm is rather generic.
/**
* Throws a Exception when not called within a task-context.
*
* This method provides a usefull error to the end-user to make him/her aware
* to use a function in the required task-context.
*
* @throws Exception
* @return Context
*/
public static function required($callerName)
{
$ctx = self::get();
if (!$ctx) {
throw new Exception("'$callerName' can only be used within a 'task()'-function!");
}
return $ctx;
}
do you still think we should move it to Context, I am fine with any solution you will accept.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think its better.
adjusted per feedback |
before this change a newcomer to this project sees errors like
when using a
ask()
function within global scope instead of atask()
.After this change the error turns into
based on a "discussion" in #371 (comment)