Rector: Online Demo no longer works: proc_open() has been disabled

Created on 20 Oct 2020  ยท  10Comments  ยท  Source: rectorphp/rector

Bug Report

| Subject | Details |
| :------------- | :---------------------------------------------------------------|
| Rector version | Unknown - using the online demo |
| Installed as | Unknown - using the online demo |

I tried to use the online demo but after clicking "Process!" and waiting for a short time, the following warning is displayed as a result:

Warning: proc_open() has been disabled for security reasons in /rector/vendor/symfony/console/Terminal.php on line 162 Warning: proc_open() has been disabled for security reasons in /rector/vendor/symfony/console/Terminal.php on line 162 In Filesystem.php line 100: Failed to create "": mkdir(): Invalid path process [-n|--dry-run] [-a|--autoload-file AUTOLOAD-FILE] [--match-git-diff] [--only ONLY] [-o|--output-format [OUTPUT-FORMAT]] [--no-progress-bar] [--output-file OUTPUT-FILE] [--cache-debug] [--clear-cache] [--] [...]

Here is my permalink: https://getrector.org/demo/ca08936c-713e-4b69-b789-ec378dc42c09

Minimal PHP Code Causing Issue

Default code of the demo.

Expected Behaviour

A result should be displayed and not a warning.

Most helpful comment

I can confirm demo is working again.

All 10 comments

Thanks for reporting :+1:

cc @JanMikes

Hi, i did some debugging.

The proc_open() is "only" warning, it is security notice and it should be strip from the error message (it is another issue ๐Ÿ˜„).

So far i have found out that something changed and while not providint --output-file in combination with --output-format it no longer works in the demo:

Json output without --output-file

root@00c2f5084b51:/project# rector process /project/rector_analyzed_file.php \
>     --autoload-file /project/rector_analyzed_file.php \
>     --output-format json \
>     --config /project/rector.php
Warning: proc_open() has been disabled for security reasons in /rector/vendor/symfony/console/Terminal.php on line 162
Warning: proc_open() has been disabled for security reasons in /rector/vendor/symfony/console/Terminal.php on line 162

In Filesystem.php line 100:

  Failed to create "": mkdir(): Invalid path


process [-n|--dry-run] [-a|--autoload-file AUTOLOAD-FILE] [--match-git-diff] [--only ONLY] [-o|--output-format [OUTPUT-FORMAT]] [--no-progress-bar] [--output-file OUTPUT-FILE] [--cache-debug] [--clear-cache] [--] [<source>...]

Default output, works well:

root@00c2f5084b51:/project# rector process /project/rector_analyzed_file.php --autoload-file /project/rector_analyzed_file.php       --config /project/rector.php
Warning: proc_open() has been disabled for security reasons in /rector/vendor/symfony/console/Terminal.php on line 162
Warning: proc_open() has been disabled for security reasons in /rector/vendor/symfony/console/Terminal.php on line 162
Rector dev-master@5bb03f2
Config file: rector.php

 4/4 [โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“] 100%


 [OK] Rector is done!

Json output with --output-file, is okay:

root@00c2f5084b51:/project# rector process /project/rector_analyzed_file.php     --autoload-file /project/rector_analyzed_file.php     --output-format json --output-file output.json     --config /project/rector.php
Warning: proc_open() has been disabled for security reasons in /rector/vendor/symfony/console/Terminal.php on line 162
Warning: proc_open() has been disabled for security reasons in /rector/vendor/symfony/console/Terminal.php on line 162
root@00c2f5084b51:/project#

Working on a fix now

@TomasVotruba Seems like not related to docker at all, it is failing even locally, looks like the --output-format json option is bugged:

โฏ /Users/janmikes/Sites/rector/bin/rector process rector_analyzed_file.php \
    --autoload-file rector_analyzed_file.php \
    --output-format json \
    --config rector.php

In Filesystem.php line 100:

  Failed to create "": mkdir(): Invalid path


process [-n|--dry-run] [-a|--autoload-file AUTOLOAD-FILE] [--match-git-diff] [--only ONLY] [-o|--output-format [OUTPUT-FORMAT]] [--no-progress-bar] [--output-file OUTPUT-FILE] [--cache-debug] [--clear-cache] [--] [<source>...]

Debug output:
```
โฏ phpx /Users/janmikes/Sites/rector/bin/rector process rector_analyzed_file.php \
--autoload-file rector_analyzed_file.php \
--output-format json \
--config rector.php \

--debug
File "/Users/janmikes/Sites/rector/bin/../vendor/autoload.php" is about to be loaded in "AutoloadIncluder::includeDependencyOrRepositoryVendorAutoloadIfExists()" on line 115"
File "rector_analyzed_file.php" is about to be loaded in "AutoloadIncluder::autoloadFromCommandLine"
File "/Users/janmikes/Sites/rector/bin/../vendor/autoload.php" is about to be loaded in "AutoloadIncluder::includeDependencyOrRepositoryVendorAutoloadIfExists()" on line 115"
File "rector_analyzed_file.php" is about to be loaded in "AutoloadIncluder::autoloadFromCommandLine"
[parsing] rector_analyzed_file.php
[refactoring] rector_analyzed_file.php
[applying] Rector\DeadCode\Rector\Stmt\RemoveUnreachableStatementRector
[applying] Rector\DeadCode\Rector\Class_\RemoveUnusedDoctrineEntityMethodAndPropertyRector
[applying] Rector\Utils\DoctrineAnnotationParserSyncer\Rector\ClassMethod\ChangeOriginalTypeToCustomRector
[applying] Rector\Utils\DoctrineAnnotationParserSyncer\Rector\ClassMethod\LogIdentifierAndResolverValueInConstantClassMethodRector
[applying] Rector\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector
[applying] Rector\DeadCode\Rector\ClassMethod\RemoveUnusedParameterRector
[applying] Rector\DeadCode\Rector\FunctionLike\RemoveOverriddenValuesRector
[applying] Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector
[applying] Rector\DeadCode\Rector\FunctionLike\RemoveCodeAfterReturnRector
[applying] Rector\DeadCode\Rector\ClassMethod\RemoveDeadConstructorRector
[applying] Rector\DeadCode\Rector\FunctionLike\RemoveDeadReturnRector
[applying] Rector\DeadCode\Rector\ClassMethod\RemoveDelegatingParentCallRector
[applying] Rector\PHPUnit\Rector\ClassMethod\RemoveEmptyTestMethodRector
[applying] Rector\DeadCode\Rector\FunctionLike\RemoveDuplicatedIfReturnRector
[applying] Rector\DeadCode\Rector\ClassMethod\RemoveDeadRecursiveClassMethodRector
[applying] Rector\CodeQuality\Rector\Return_\SimplifyUselessVariableRector
[post rectors] rector_analyzed_file.php
[printing] rector_analyzed_file.php
PHP Fatal error: Uncaught Symfony\Component\Filesystem\Exception\IOException: Failed to create "": mkdir(): Invalid path in /Users/janmikes/Sites/rector/vendor/symfony/filesystem/Filesystem.php:100
Stack trace:

0 /Users/janmikes/Sites/rector/vendor/symfony/filesystem/Filesystem.php(650): Symfony\Component\Filesystem\Filesystem->mkdir('')

1 /Users/janmikes/Sites/rector/packages/changes-reporting/src/Output/JsonOutputFormatter.php(105): Symfony\Component\Filesystem\Filesystem->dumpFile('', '{\n "meta": {...')

2 /Users/janmikes/Sites/rector/src/Console/Command/ProcessCommand.php(242): Rector\ChangesReporting\Output\JsonOutputFormatter->report(Object(Rector\ChangesReporting\Application\ErrorAndDiffCollector))

3 /Users/janmikes/Sites/rector/vendor/symfony/console/Command/Command.php(258): Rector\Core\Console\Command\ProcessCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

4 /Users/janmikes/Sites/rector/src/Console/Command/AbstractCommand.php(44): Sym in /Users/janmikes/Sites/rector/vendor/symfony/filesystem/Filesystem.php on line 100

Fatal error: Uncaught Symfony\Component\Filesystem\Exception\IOException: Failed to create "": mkdir(): Invalid path in /Users/janmikes/Sites/rector/vendor/symfony/filesystem/Filesystem.php:100
Stack trace:

0 /Users/janmikes/Sites/rector/vendor/symfony/filesystem/Filesystem.php(650): Symfony\Component\Filesystem\Filesystem->mkdir('')

1 /Users/janmikes/Sites/rector/packages/changes-reporting/src/Output/JsonOutputFormatter.php(105): Symfony\Component\Filesystem\Filesystem->dumpFile('', '{\n "meta": {...')

2 /Users/janmikes/Sites/rector/src/Console/Command/ProcessCommand.php(242): Rector\ChangesReporting\Output\JsonOutputFormatter->report(Object(Rector\ChangesReporting\Application\ErrorAndDiffCollector))

3 /Users/janmikes/Sites/rector/vendor/symfony/console/Command/Command.php(258): Rector\Core\Console\Command\ProcessCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

4 /Users/janmikes/Sites/rector/src/Console/Command/AbstractCommand.php(44): Sym in /Users/janmikes/Sites/rector/vendor/symfony/filesystem/Filesystem.php on line 100

It might be relate to composer v2. I had to revert to composer v1, to get version in --output-format json - https://github.com/rectorphp/rector/blob/5bb03f2fcb40216f374f94df8cf2e726a729e6be/packages/changes-reporting/src/Output/JsonOutputFormatter.php#L55

@TomasVotruba @samsonasik this changed line caused it: https://github.com/rectorphp/rector/commit/ba4ec9de094cf4e2f6414f564fe45070067773a1#diff-a3ae622b45e9d5860b9384df1217ffdf3a921e9263f5ac059f4a0babad33d7caR130

It is obvious from the stacktrace in comment above, that $fileName from option is resolved to empty string '' instead of null.

Fix is easy, already writing a fix, though i am not sure how to write test for it ๐Ÿ˜ข

Good job! Hm, nullable :/ No need for test here, I think.

I wonder if there should be some rule to avoid this, like console optoin always returns value, not null

I can confirm demo is working again.

Thank you :bow:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

peterrehm picture peterrehm  ยท  4Comments

sidux picture sidux  ยท  5Comments

pavarnos picture pavarnos  ยท  4Comments

HDVinnie picture HDVinnie  ยท  3Comments

donbrico picture donbrico  ยท  4Comments