phpinsights icon indicating copy to clipboard operation
phpinsights copied to clipboard

LogicException Unable to find data for Pivot Models in Laravel

Open DiplNext opened this issue 2 years ago β€’ 7 comments

Q A
Bug report? yes/no
Feature request? yes/no
Library version x.y.z

image DepartmentStaffStructure.php it's model for pivot table if I excluded this model all works perfectlly

DiplNext avatar Jun 16 '22 09:06 DiplNext

I'm facing the same problem with Actions (https://laravelactions.com/).

I downgraded to 2.3.0 and the exception isn't fire anymore.

deniscsz avatar Jun 22 '22 02:06 deniscsz

Thanks for reporting, we will look into this and see if we can replicate this issue

JustSteveKing avatar Jun 22 '22 07:06 JustSteveKing

I've got the same issue. I've tried to downgrade through all the versions (v2) and that just gives us different files throwing the error.

Some things that make no sense:

  1. Works on 3 different locals. An Ubuntu and two Homestead vagrants
  2. Fails in our CI/CD with this error
  3. Adding --fix doesn't skip the cache. I could be wrong on it but it seems that should skip that portion throwing the exception.
  4. It runs through everything before throwing the error
$ php artisan insights app/ --fix --format=codeclimate  --min-quality=95 --min-style=100  > codeclimate-report.json
   0/724 [β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘]   0%
 722/724 [β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–‘]  99%
 724/724 [β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“] 100%
Uploading artifacts for failed job

If you can think of anything to try or dump/log let me know. I'll start playing around when I have some time tomorrow.

guywarner avatar Jun 28 '22 23:06 guywarner

Is there any chance of seeing what it is failing on class wise? Also the fll backtrace will help in seeing what is making it trip up πŸ˜ƒ

JustSteveKing avatar Jun 29 '22 07:06 JustSteveKing

I apologize that I didn't have enough time to fully attempt to debug this today. Here's some information that I was able to gather.

We are using docker in the CI runner: https://hub.docker.com/r/lorisleiva/laravel-docker (latest) running PHP 8.1

Error

   LogicException 

  Unable to find data for /builds/lenderfeed/monitorbase.com/app/Mail/CallNotification.php

  at vendor/nunomaduro/phpinsights/src/Domain/Runner.php:184
    180β–•     {
    181β–•         $cacheKey = 'insights.' . $this->cacheKey . '.' . md5($file->getContents());
    182β–•         // Do not use cache if fix is enabled to force processors to handle it
    183β–•         if (! $this->cache->has($cacheKey)) {
  ➜ 184β–•             throw new \LogicException('Unable to find data for ' . $file->getPathname());
    185β–•         }
    186β–• 
    187β–•         $this->loadDetailsCache($cacheKey);
    188β–•

      [2m+4 vendor frames [22m
  5   [internal]:0
      NunoMaduro\PhpInsights\Domain\Insights\InsightCollectionFactory::NunoMaduro\PhpInsights\Domain\Insights\{closure}("PHP_CodeSniffer\Standards\Generic\Sniffs\CodeAnalysis\UnnecessaryFinalModifierSniff")

      [2m+17 vendor frames [22m
  23  artisan:35
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

Stack trace:

[2022-06-29 10:28:19] local.ERROR: Unable to find data for /builds/lenderfeed/monitorbase.com/app/Console/Commands/Email/SendStatsEmail.php {"exception":"[object] (LogicException(code: 0): Unable to find data for /builds/lenderfeed/monitorbase.com/app/Console/Commands/Email/SendStatsEmail.php at /builds/lenderfeed/monitorbase.com/vendor/nunomaduro/phpinsights/src/Domain/Runner.php:184)
[stacktrace]
#0 /builds/lenderfeed/monitorbase.com/vendor/nunomaduro/phpinsights/src/Domain/Runner.php(170): NunoMaduro\\PhpInsights\\Domain\\Runner->processFile(Object(Symfony\\Component\\Finder\\SplFileInfo))
#1 /builds/lenderfeed/monitorbase.com/vendor/nunomaduro/phpinsights/src/Domain/Insights/InsightFactory.php(98): NunoMaduro\\PhpInsights\\Domain\\Runner->run()
#2 /builds/lenderfeed/monitorbase.com/vendor/nunomaduro/phpinsights/src/Domain/Insights/InsightFactory.php(69): NunoMaduro\\PhpInsights\\Domain\\Insights\\InsightFactory->runInsightCollector(Object(Symfony\\Component\\Console\\Output\\StreamOutput))
#3 /builds/lenderfeed/monitorbase.com/vendor/nunomaduro/phpinsights/src/Domain/Insights/InsightCollectionFactory.php(67): NunoMaduro\\PhpInsights\\Domain\\Insights\\InsightFactory->makeFrom('PHP_CodeSniffer...', Object(Symfony\\Component\\Console\\Output\\StreamOutput))
#4 [internal function]: NunoMaduro\\PhpInsights\\Domain\\Insights\\InsightCollectionFactory::NunoMaduro\\PhpInsights\\Domain\\Insights\\{closure}('PHP_CodeSniffer...')
#5 /builds/lenderfeed/monitorbase.com/vendor/nunomaduro/phpinsights/src/Domain/Insights/InsightCollectionFactory.php(68): array_map(Object(Closure), Array)
#6 /builds/lenderfeed/monitorbase.com/vendor/nunomaduro/phpinsights/src/Application/Console/Analyser.php(36): NunoMaduro\\PhpInsights\\Domain\\Insights\\InsightCollectionFactory->get(Array, Object(Symfony\\Component\\Console\\Output\\StreamOutput))
#7 /builds/lenderfeed/monitorbase.com/vendor/nunomaduro/phpinsights/src/Application/Console/Commands/AnalyseCommand.php(65): NunoMaduro\\PhpInsights\\Application\\Console\\Analyser->analyse(Object(NunoMaduro\\PhpInsights\\Application\\Console\\Formatters\\Multiple), Object(Symfony\\Component\\Console\\Output\\StreamOutput))
#8 /builds/lenderfeed/monitorbase.com/vendor/nunomaduro/phpinsights/src/Application/Adapters/Laravel/Commands/InsightsCommand.php(72): NunoMaduro\\PhpInsights\\Application\\Console\\Commands\\AnalyseCommand->__invoke(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#9 /builds/lenderfeed/monitorbase.com/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): NunoMaduro\\PhpInsights\\Application\\Adapters\\Laravel\\Commands\\InsightsCommand->handle()
#10 /builds/lenderfeed/monitorbase.com/vendor/laravel/framework/src/Illuminate/Container/Util.php(41): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#11 /builds/lenderfeed/monitorbase.com/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure(Object(Closure))
#12 /builds/lenderfeed/monitorbase.com/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
#13 /builds/lenderfeed/monitorbase.com/vendor/laravel/framework/src/Illuminate/Container/Container.php(651): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
#14 /builds/lenderfeed/monitorbase.com/vendor/laravel/framework/src/Illuminate/Console/Command.php(136): Illuminate\\Container\\Container->call(Array)
#15 /builds/lenderfeed/monitorbase.com/vendor/symfony/console/Command/Command.php(308): Illuminate\\Console\\Command->execute(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#16 /builds/lenderfeed/monitorbase.com/vendor/laravel/framework/src/Illuminate/Console/Command.php(121): Symfony\\Component\\Console\\Command\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#17 /builds/lenderfeed/monitorbase.com/vendor/symfony/console/Application.php(998): Illuminate\\Console\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#18 /builds/lenderfeed/monitorbase.com/vendor/symfony/console/Application.php(299): Symfony\\Component\\Console\\Application->doRunCommand(Object(NunoMaduro\\PhpInsights\\Application\\Adapters\\Laravel\\Commands\\InsightsCommand), Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#19 /builds/lenderfeed/monitorbase.com/vendor/symfony/console/Application.php(171): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#20 /builds/lenderfeed/monitorbase.com/vendor/laravel/framework/src/Illuminate/Console/Application.php(102): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#21 /builds/lenderfeed/monitorbase.com/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(129): Illuminate\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#22 /builds/lenderfeed/monitorbase.com/artisan(35): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#23 {main}
"} 

File:

<?php

namespace App\Mail;

use App\Mail\Mailable;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;

class CallNotification extends Mailable
{
    use Queueable, SerializesModels;
    public $message;
    public $status;
    public $subject;
    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct(public $camp, public $prospect, public $call, public $user)
    {
        $this->message = '';
        $this->status = '';
        $this->subject = '';
    }
    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        $this->status = 'New Call';
        $this->subject = 'New Call Notification';
        if ($this->call->DialCallStatus == 'no-answer' || $this->call->DialCallDuration < 30) {
            $this->status = 'Missed Call';
            $this->subject = 'Missed Call Notification';
        }

        if ($this->call->DialCallStatus == 'failed') {
            $this->status = 'Failed Call';
            $this->subject = 'Failed Call Notification';
        }
        return $this->markdown('email.user.call.notification')
            ->text('email.user.call.notification_plain')
            ->subject($this->subject);
    }
}

If we remove the file then it will change to the next file in the folder. Remove the folder and it'll throw it in the next folder.

The first interesting item is if we define app/ in the artisan call we get this file as the error. If we omit it we get a different file.

But, the most interesting thing is if we don't run the artisan command but from the vendor directory, it runs and completes just fine.

guywarner avatar Jun 29 '22 23:06 guywarner

New development. Just suddenly started working again.

v2.4

But, after running --fix whatever files it changed, it breaks againβ€”going to add it back into our regular CI/CD pipeline and see if we can pinpoint what's making it lose its mind.

guywarner avatar Jul 12 '22 22:07 guywarner

Thanks @guywarner - keep us updated?

JustSteveKing avatar Jul 13 '22 07:07 JustSteveKing

same strange problem here.

Within our team PHPInsights fails (with the LogicException mentioned above). It always fails for the same file, however the file is a random(?) different one for every team member and in our pipeline.

I put the following debugging code in vendor/nunomaduro/phpinsights/src/Domain/Runner.php:run():

if ($file->getPathname() == '/some/folder/app/Traits/EnumHasFormOptions.php') {
    $cacheKey = 'insights.' . $this->cacheKey . '.' . md5($file->getContents());
    dd($this->cache, $cacheKey, $this->cache->has($cacheKey), $this->cache->get($cacheKey));

}

the output is that

  • $this->cache->has($cacheKey) is false
  • $this->cache->get($cacheKey)) returns null
  • $cacheKey returns some key, let's say insights.f5f9b0a492315f7a20b0c1e9da45082e.04a4c3d2e4ee526b75d6f177f6591bb9
  • interestingly in the dump of the cache object, this key appears in the ids, so $this->cache->has(...) should return true? grafik

cpfpolkehn avatar Aug 18 '22 15:08 cpfpolkehn

in our case the root cause was / is https://github.com/nunomaduro/phpinsights/issues/593

cpfpolkehn avatar Aug 18 '22 19:08 cpfpolkehn

same strange problem here.

Within our team PHPInsights fails (with the LogicException mentioned above). It always fails for the same file, however the file is a random(?) different one for every team member and in our pipeline. ...

my comment with some explanation https://github.com/nunomaduro/phpinsights/issues/593#issuecomment-1220248274

LogicException may occur when Runner start Symfony\Component\Process\Process and background process fail for different reasons.

In this case process failed because of use PhpCsFixer\Diff\Differ as BaseDiffer; I did PR which fix recent LogicException issue https://github.com/nunomaduro/phpinsights/pull/591

real-splendid avatar Aug 19 '22 07:08 real-splendid

This should be fixed in 2.5.0. Please let us know if you are still having issues

cmgmyr avatar Sep 03 '22 11:09 cmgmyr