Skip to content
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

Display Exception in Atk callback #691

Closed
mvorisek opened this issue Apr 16, 2019 · 4 comments
Closed

Display Exception in Atk callback #691

mvorisek opened this issue Apr 16, 2019 · 4 comments
Assignees

Comments

@mvorisek
Copy link
Member

mvorisek commented Apr 16, 2019

Currently, when callback is used and an Exception occurs, simple message:

!! Callback requested, but never reached. You may be missing some arguments in...

is displayed.

Currently it is very hard to understand what is going wrong.

At least the Exception message should be displayed in the error (located in

ui/src/App.php

Line 415 in 695baeb

$this->terminate('!! Callback requested, but never reached. You may be missing some arguments in '.$_SERVER['REQUEST_URI']);
).

And also HTTP code = 500 should be returned.

@funyx
Copy link
Contributor

funyx commented Apr 16, 2019

if (isset($_GET['__atk_callback']) && $this->catch_runaway_callbacks) {
            $this->terminate('!! Callback requested, but never reached. You may be missing some arguments in '.$_SERVER['REQUEST_URI']);
        }

that is the flag in the check:

 /**
     * Will display error if callback wasn't triggered.
     *
     * @var bool
     */
    public $catch_runaway_callbacks = true;

@mvorisek
Copy link
Member Author

Yes, when an exception is throw inside the callback, the catch_runaway_callbacks property is not cleared. So it should be cleared before the callback is processed and the result should be the exception message / handler result.

But an HTTP code = 500 should be set in general before any error output, ie. here too.

@funyx
Copy link
Contributor

funyx commented Apr 18, 2019

I guess that flag only checks if the function is reachable/exists..
So if you want an exception you should implement it like this..

$this->addHook('beforeOutput,',function(){
  throw new \HookBreaker(new Exception('wops',1234));
});
try {
new App();
} catch ( \HookBreaker $e) {
// maybe switch $e->getCode()..
throw $e;
}

@mvorisek
Copy link
Member Author

Already fixed in the last version on this line:

ui/src/App.php

Line 251 in 695baeb

$l->catch_runaway_callbacks = false;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants