spatie/laravel-server-monitor

Trying to get property of non-object after delete a host

Closed this issue · 3 comments

After delete a host with server-monitor:delete-host command, when I try to run or list checks I get this error:

[ErrorException]
  Trying to get property of non-object

This is the trace when I executed the server-monitor:list-checks command with -v argument:

Exception trace:
 () at .../server-monitor/laravel/vendor/spatie/laravel-server-monitor/src/Commands/ListChecks.php:75
 Illuminate\Foundation\Bootstrap\HandleExceptions->handleError() at .../server-monitor/laravel/vendor/spatie/laravel-server-monitor/src/Commands/ListChecks.php:75
 Spatie\ServerMonitor\Commands\ListChecks->Spatie\ServerMonitor\Commands\{closure}() at n/a:n/a
 array_map() at .../server-monitor/laravel/vendor/laravel/framework/src/Illuminate/Support/Collection.php:684
 Illuminate\Support\Collection->map() at .../server-monitor/laravel/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Collection.php:130
 Illuminate\Database\Eloquent\Collection->map() at .../server-monitor/laravel/vendor/spatie/laravel-server-monitor/src/Commands/ListChecks.php:82
 Spatie\ServerMonitor\Commands\ListChecks->getTableRows() at .../server-monitor/laravel/vendor/spatie/laravel-server-monitor/src/Commands/ListChecks.php:33
 Spatie\ServerMonitor\Commands\ListChecks->unhealthyChecks() at .../server-monitor/laravel/vendor/spatie/laravel-server-monitor/src/Commands/ListChecks.php:23
 Spatie\ServerMonitor\Commands\ListChecks->handle() at n/a:n/a
 call_user_func_array() at .../server-monitor/laravel/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:29
 Illuminate\Container\BoundMethod::Illuminate\Container\{closure}() at .../server-monitor/laravel/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:87
 Illuminate\Container\BoundMethod::callBoundMethod() at .../server-monitor/laravel/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:31
 Illuminate\Container\BoundMethod::call() at .../server-monitor/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php:524
 Illuminate\Container\Container->call() at .../server-monitor/laravel/vendor/laravel/framework/src/Illuminate/Console/Command.php:182
 Illuminate\Console\Command->execute() at .../server-monitor/laravel/vendor/symfony/console/Command/Command.php:262
 Symfony\Component\Console\Command\Command->run() at .../server-monitor/laravel/vendor/laravel/framework/src/Illuminate/Console/Command.php:167
 Illuminate\Console\Command->run() at .../server-monitor/laravel/vendor/spatie/laravel-server-monitor/src/Commands/BaseCommand.php:16
 Spatie\ServerMonitor\Commands\BaseCommand->run() at .../server-monitor/laravel/vendor/symfony/console/Application.php:826
 Symfony\Component\Console\Application->doRunCommand() at .../server-monitor/laravel/vendor/symfony/console/Application.php:189
 Symfony\Component\Console\Application->doRun() at .../server-monitor/laravel/vendor/symfony/console/Application.php:120
 Symfony\Component\Console\Application->run() at .../server-monitor/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:123
 Illuminate\Foundation\Console\Kernel->handle() at .../server-monitor/laravel/artisan:35

I'm using the server-monitor-app, but I think the problem is with the component.

I have browsing the database and found the checks for the deleted host(s). When I deleted those records, the issue is gone.

So, it seems the solution is the delete-host command must delete the checks for the deleted host?

Hi @orumad

I couldn't replicate the issue but I think foreign key constraints might be disable on your sqlite database. I've tagged a new release (1.0.1) for the server-monitor-app that includes a migration to enable foreign key constraints.
Could you try to install the project again and see if it works now?

Thanks!

Hi @AlexVanderbist ,

I just install the last release (1.0.1) for the server-monitor-app but the problem still remains. Maybe the problem is something related to my sqlite version (I'm on macOS).

FYI I've opened the sqlite database with a sqlite database browser and saw the relationship between hosts and checks tables, but it seems the cascade delete is not working.

Anyway I've resolved the issue deleting the checks records manually.

Thanks for your help!