Which hook is the first one that is fired?

Hi All,

I’m looking for a hook that preferably only gets fired once and as soon as possible on runtime. Any ideas?

Sam

For each event with a hook there is a before and an after hook. But what do you want to achieve?

May be; after loading Kirby and all the plugins the hook run: system.loadPlugins:after :thinking:

I want to register bugsnag for error monitoring. Obviously I can do this in the index.php (that’s what I do now) but I would like to make a plugin so I’m looking for a way to inject this as soon as possible via the plugin hooks or something. (so @ahmetbora loadPlugins:after is too late since you won’t get catch the plugin errors then)

Have you tried to install it via composer by making a new kirby plugin?

I’m not sure what you are getting at? Getting bugsnag in use and installed isn’t really the problem here. I just want to create a Kirby plugin that gets fired as soon as possible to register the bugsnag error handler thus I’m searching for the best and optimal way to do that :relaxed:

You are right that I do not fully understand :sweat_smile:

Hmm, I’m not sure with the plugin but I think you could do it with the fatal option. :thinking:

// /site/config/config.php
return [
  'debug' => true,
  'fatal' => function($kirby, $exception) { // $exception param is since 3.5.5
    $bugsnag = \Bugsnag\Client::make(); // need setup with api keys, endpoints, etc..
    $bugsnag->notifyException($exception);
    
    include $kirby->root('templates') . '/fatal.php';
  }
];

I hope this meets your needs.

You don’t even have to attach on fatal, You can register it to the errorHandler directly. The main part i’m in search for is what’s the best way to get this setup in a simple plugin with a hook on a smart place :wink:

ex. (this code already works if I, for example put it in the index.php above the render)

if($kirby->option('bugsnag.key') && $kirby->option('debug') === false)
{
    $bugsnag = Bugsnag\Client::make($kirby->option('bugsnag.key'));
    Bugsnag\Handler::register($bugsnag);
}

Pinging @lukasbestle to get find out any tricks about that.

If system.loadPlugins:after is too late, the only option is to register the handler directly from your plugin’s index.php. But accessing the $kirby object from there is not supported as it can cause issues in the loading order. So for best reliability you won’t be able to make your plugin registration depend on Kirby options.