phpinsights icon indicating copy to clipboard operation
phpinsights copied to clipboard

Syntax JsonException issue

Open rick-clweb opened this issue 1 year ago • 8 comments

Q A
Bug report? yes
Feature request? no
Library version 2.8.0
Laravel version 9.19.0
PHP version 8.0.2

File: vendor/nunomaduro/phpinsights/src/Domain/Insights/SyntaxCheck.php

Error: 71/74 [==========================>-] 95% < 1 sec

JsonException (4) Syntax error

Error occurs on line 56. $output = json_decode($process->getOutput(), true, 512, JSON_THROW_ON_ERROR);

Fix: The error is removed if you remove the JSON_THROW_ON_ERROR flag.

Exception trace:

- json_decode() at local_project_path\vendor\nunomaduro\phpinsights\src\Domain\Insights\SyntaxCheck.php:56
-  NunoMaduro\PhpInsights\Domain\Insights\SyntaxCheck->process() at local_project_path\vendor\nunomaduro\phpinsights\src\Domain\Runner.php:164
-  NunoMaduro\PhpInsights\Domain\Runner->run() at local_project_path\vendor\nunomaduro\phpinsights\src\Domain\Insights\InsightFactory.php:98
-  NunoMaduro\PhpInsights\Domain\Insights\InsightFactory->runInsightCollector() at local_project_path\vendor\nunomaduro\phpinsights\src\Domain\Insights\InsightFactory.php:69
-  NunoMaduro\PhpInsights\Domain\Insights\InsightFactory->makeFrom() at local_project_path\vendor\nunomaduro\phpinsights\src\Domain\Insights\InsightCollectionFactory.php:67
-  NunoMaduro\PhpInsights\Domain\Insights\InsightCollectionFactory::NunoMaduro\PhpInsights\Domain\Insights\{closure}() at n/a:n/a
-  array_map() at local_project_path\vendor\nunomaduro\phpinsights\src\Domain\Insights\InsightCollectionFactory.php:66
-  NunoMaduro\PhpInsights\Domain\Insights\InsightCollectionFactory->get() at local_project_path\vendor\nunomaduro\phpinsights\src\Application\Console\Analyser.php:36
-  NunoMaduro\PhpInsights\Application\Console\Analyser->analyse() at local_project_path\vendor\nunomaduro\phpinsights\src\Application\Console\Commands\AnalyseCommand.php:65
-  NunoMaduro\PhpInsights\Application\Console\Commands\AnalyseCommand->__invoke() at n/a:n/a
-  call_user_func() at local_project_path\vendor\nunomaduro\phpinsights\src\Application\Console\Commands\InvokableCommand.php:41
-  NunoMaduro\PhpInsights\Application\Console\Commands\InvokableCommand->execute() at local_project_path\vendor\symfony\console\Command\Command.php:312
-  Symfony\Component\Console\Command\Command->run() at local_project_path\vendor\symfony\console\Application.php:1022
-  Symfony\Component\Console\Application->doRunCommand() at local_project_path\vendor\symfony\console\Application.php:314
-  Symfony\Component\Console\Application->doRun() at local_project_path\vendor\symfony\console\Application.php:168
-  Symfony\Component\Console\Application->run() at local_project_path\vendor\nunomaduro\phpinsights\bin\phpinsights:42
-  {closure}() at local_project_path\vendor\nunomaduro\phpinsights\bin\phpinsights:43
-  include() at local_project_path\vendor\bin\phpinsights:120

Process data

Symfony\Component\Process\Process {#3034 // vendor\nunomaduro\phpinsights\src\Domain\Insights\SyntaxCheck.php:56
  -callback: null
  -hasCallback: false
  -commandline: "local_project_path\vendor\bin\parallel-lint.bat --no-colors --no-progress --json --exclude "bower_components" --exclude "node_modules" --exclude "vendor" --exclude "vendor-bin" --exclude ".phpstorm.meta
.php" --exclude "config" --exclude "storage" --exclude "resources" --exclude "bootstrap" --exclude "nova" --exclude "database" --exclude "server.php" --exclude "_ide_helper.php" --exclude "_ide_helper_models.php" --exclude "app/Providers/TelescopeServiceProvider.php" --exclude "public" --exclude "vendor" --exclude "tests" --exclude "Tests" --exclude "test" --exclude "Test" ."
  -cwd: "local_project_path"
  -env: []
  -input: null
  -starttime: 1680511684.1632
  -lastOutputTime: 1680511684.3713
  -timeout: 60.0
  -idleTimeout: null
  -exitcode: 1
  -fallbackStatus: []
  -processInformation: array:8 [
    "command" => "cmd /V:ON /E:ON /D /C (local_project_path\vendor\bin\parallel-lint.bat --no-colors --no-progress --json --exclude "bower_components" --exclude "node_modules" --exclude "vendor" --exclude "vendor-bin" -
-exclude ".phpstorm.meta.php" --exclude "config" --exclude "storage" --exclude "resources" --exclude "bootstrap" --exclude "nova" --exclude "database" --exclude "server.php" --exclude "_ide_helper.php" --exclude "_ide_helper_models.php" --exclude "app/Providers/TelescopeServiceProvider.php" --exclude "public" --exclude "vendor" --exclude "tests" --exclude "Tests" --exclude "test" --exclude "Test" .) 1>"local_path\AppData\Local\Temp\sf_proc_00.out" 2>"local_path\AppData\Local\Temp\sf_proc_00.err""
    "pid" => 3004
    "running" => false
    "signaled" => false
    "stopped" => false
    "exitcode" => 1
    "termsig" => 0
    "stopsig" => 0
  ]
  -outputDisabled: false
  -stdout: stream resource {@3420
    wrapper_type: "PHP"
    stream_type: "TEMP"
    mode: "w+b"
    unread_bytes: 0
    seekable: true
    uri: "php://temp/maxmemory:1048576"
    options: []
  }
  -stderr: stream resource {@3422
    wrapper_type: "PHP"
    stream_type: "TEMP"
    mode: "w+b"
    unread_bytes: 0
    seekable: true
    uri: "php://temp/maxmemory:1048576"
    options: []
  }
  -process: Closed resource @3436
  -status: "terminated"
  -incrementalOutputOffset: 0
  -incrementalErrorOutputOffset: 0
  -tty: false
  -pty: false
  -options: array:2 [
    "suppress_errors" => true
    "bypass_shell" => true
  ]
  -useFileHandles: true
  -processPipes: Symfony\Component\Process\Pipes\WindowsPipes {#3035
    +pipes: []
    -inputBuffer: ""
    -input: null
    -blocked: false
    -lastError: null
    -files: array:2 [
      1 => "local_path\AppData\Local\Temp\sf_proc_00.out"
      2 => "local_path\AppData\Local\Temp\sf_proc_00.err"
    ]
    -fileHandles: []
    -lockHandles: []
    -readBytes: array:2 [
      1 => 0
      2 => 123
    ]
    -haveReadSupport: true
  }
  -latestSignal: null
}

rick-clweb avatar Apr 03 '23 08:04 rick-clweb

I have the same problem.

Library version | 2.8.0 Laravel version | 9.19.0 PHP version | 8.0.2

pelmered avatar Jul 24 '23 13:07 pelmered

Quick solution: in config/insights.php add \NunoMaduro\PhpInsights\Domain\Insights\SyntaxCheck::class to remove key

'remove' => [
    ...
    \NunoMaduro\PhpInsights\Domain\Insights\SyntaxCheck::class,
],

But I think it's not perfect

kleninmaxim avatar Aug 15 '23 14:08 kleninmaxim

Getting this error as well @kleninmaxim suggestion works for now.

andruu avatar Sep 09 '23 04:09 andruu

Didn't solve the issue for me.

Library version | 2.8.0 Laravel version | 9.52.15 PHP version | 8.1.23

EPuigdemont avatar Sep 22 '23 15:09 EPuigdemont

Hello,

I had the exact same issue, I am using Latest Herd and PHP 8.2.

Right after installing the package I ran artisan insight I got this:

Screenshot 2023-09-24 at 22 25 06

Then after applying the “workaround” above it got resolved (and beautiful):

Screenshot 2023-09-24 at 22 35 01

Thanks.

aldoyh avatar Sep 24 '23 19:09 aldoyh

having the same problem (well in line 57 now) on v2.10.0 the problem in my case is that

$process->getOutput() results in an empty string, and there is no check for it... so JSON_THROW_ON_ERROR fires...

on php >= 8.3.0 it could help to pass $process->getOutput() through json_validate

hexathos avatar Dec 20 '23 00:12 hexathos

i'm experiencing the same. It worked before, but not after moving from homestead to herd for windows (beta). The above fix by adding the file to the remove config worked for me too.

AndreasHerss avatar Mar 23 '24 16:03 AndreasHerss

This issue makes the library completely unusable, and am surprised this hasn't been escalated to resolve =\ Having the same issue with 2.11.0, PHP 8.2.16, also related to Herd - looks like a permissions issue?

I got the actual error (rather than the useless "JsonError" response), and saw this:

{"type":"JakubOnderka\PhpParallelLint\RunTimeException","message":"Unable to execute '/Users/.../Library/Application Support/Herd/bin/php82'.","code":0}

The workaround above helped (also not particularly interested in syntax checks by the library), but this may not be a solution for some.

kirkbushell avatar May 21 '24 00:05 kirkbushell