nova-command-runner icon indicating copy to clipboard operation
nova-command-runner copied to clipboard

Assignment of null to a string property since the new version

Open jonnywilliamson opened this issue 1 year ago • 2 comments

Hi there,

I've been using this nova plugin for quite a while now with no issues, until a few days ago after I updated it. Haven't changed anything in the config etc, but when I run my command from the nova dashboard I get a server 500 error.

The error is as follows in the log:

[2024-04-23 09:07:07] production.ERROR: Cannot assign null to property Stepanenko3\NovaCommandRunner\Dto\RunDto::$run_by of type string {"userId":48204,"exception":"[object] (TypeErro
[stacktrace]
#0 /home/forge/crewapps.co/vendor/stepanenko3/nova-command-runner/src/Http/Controllers/CommandsController.php(117): Stepanenko3\\NovaCommandRunner\\Dto\\RunDto->__construct()
#1 /home/forge/crewapps.co/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(46): Stepanenko3\\NovaCommandRunner\\Http\\Controllers\\CommandsController->run()
#2 /home/forge/crewapps.co/vendor/laravel/framework/src/Illuminate/Routing/Route.php(260): Illuminate\\Routing\\ControllerDispatcher->dispatch()
#3 /home/forge/crewapps.co/vendor/laravel/framework/src/Illuminate/Routing/Route.php(206): Illuminate\\Routing\\Route->runController()
#4 /home/forge/crewapps.co/vendor/laravel/framework/src/Illuminate/Routing/Router.php(806): Illuminate\\Routing\\Route->run()

Having a look at the RunDto I see a recent change in commit

https://github.com/stepanenko3/nova-command-runner/commit/954ae263e96107acc35818ab4e3d81deefba440b#diff-34ea08736004df131df35da01543bdd3ea44ce5506612c743557fb6b63833cf3L9-L21

Where you marked everything apart from $run_by as a nullable string

However in your CommandsController.php you try and run the command with a new RunDTO() object that has no parameters and so it's trying to set $run_by as null and so throwing the error. (I think).

https://github.com/stepanenko3/nova-command-runner/blob/main/src/Http/Controllers/CommandsController.php#L117

Not sure what would be best here, but thought I'd just highlight it as an issue as I can't get the commands to run online anymore.

Thanks.

jonnywilliamson avatar Apr 23 '24 10:04 jonnywilliamson

Actually having another look at it I see that the issue might be the same issue as https://github.com/stepanenko3/nova-command-runner/issues/20

The constructor of RunDTO sets the run_by to the name of auth user .

https://github.com/stepanenko3/nova-command-runner/blame/0d1bf7864e4dfb0a78c7e5590937611564b20258/src/Dto/RunDto.php#L27

But my users don't have a name field. They have a first_name field instead. So this is where the null is coming from.

It's only become apparent because of the change of adding type checking to the class properties.

jonnywilliamson avatar Apr 23 '24 10:04 jonnywilliamson

Opened #42 to fix this. Although the package is still broken because of #30

As an alternative, I'd suggest either downgrading to 4.2.7 or using 4.3.4 and adding this to your user model:

public function getNameAttribute(): string
{
    return $this->first_name;
}

kiritokatklian avatar May 19 '24 11:05 kiritokatklian