Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows Compatibility: [ERROR] Command failed #17

Open
rafal-kos opened this issue Oct 26, 2018 · 38 comments
Open

Windows Compatibility: [ERROR] Command failed #17

rafal-kos opened this issue Oct 26, 2018 · 38 comments
Labels
bug Something isn't working help wanted Extra attention is needed windows

Comments

@rafal-kos
Copy link

Hello,

I am trying to run the tool on windows Git Bash :
vendor/bin/cache-clean.js config full_page
but in result I have this error :
[ERROR] Command failed: php -r 'echo json_encode((require "D:\projects\example\magento/app/etc/env.php") ?? []);'

Looks like there a problem with slash. When I run this command
php -r 'echo json_encode((require "D:/projects/example/magento/app/etc/env.php") ?? []);'
I am getting correct results.

Is it possible to get some fix for hat? Thanks in advance.

@Vinai
Copy link
Contributor

Vinai commented Oct 31, 2018

Thanks for opening the issue, I‘ll push a branch some time soon and then would like to ask you to test if it works for you.

@Vinai Vinai added the bug Something isn't working label Oct 31, 2018
@rafal-kos
Copy link
Author

OK. Thanks for info.

@Vinai
Copy link
Contributor

Vinai commented Oct 31, 2018

I require your help to get the tool working on windows.
Can you please install the win-compatibility branch and let me know how that works?

composer remove --dev mage2tv/magento-cache-clean
composer require --dev mage2tv/magento-cache-clean:dev-win-compatibility

I expect a new error to occur. I'll try to fix one after the other until it works on windows too. Please be patient with me until it works. I appreciate your help.

@rafal-kos
Copy link
Author

I checked the new branch. Still the same issue :

[ERROR] Command failed: php -r 'echo json_encode((require "D:\projects\example\magento/app\etc\env.php") ?? []);'

@rafal-kos
Copy link
Author

I see in file system.cljs

(defn- win? []
  (= "win32" (.-platform process)))

On my machine I am using GIT Bash (mingw64). Maybe different platform is used here? Any chance to add some debug here?

@Vinai
Copy link
Contributor

Vinai commented Nov 1, 2018

According to the documentation win32 is the operating identifier returned by nodejs on any windows host.

You can see the value on your host by running the following command in your teminal

node -e 'console.log(process.platform)'

@Vinai Vinai added the more-info-required Further information is requested label Nov 5, 2018
@Vinai
Copy link
Contributor

Vinai commented Nov 5, 2018

Got info from third party using Win10:

aaron@AVALANCHE MINGW64 ~
$ node -e 'console.log(process.platform)'
win32

@Vinai Vinai removed the more-info-required Further information is requested label Nov 5, 2018
@rafal-kos
Copy link
Author

Yes. It looks the same on my machine. Any chance to get not minified cache-clean.js? I tried to build it on WIN without success.

@Vinai
Copy link
Contributor

Vinai commented Nov 7, 2018

I've pushed an update to the win-compatibility branch.
This time all file system methods get path arguments on windows with backslashes instead of slashes.
There still might be other issues though.

Could you please do me a favor and update the branch again?

composer remove --dev mage2tv/magento-cache-clean
composer require --dev mage2tv/magento-cache-clean:dev-win-compatibility

Please also run cache-clean.js --version to confirm the correct build is being used. It should display the release name 0.0.22-dev-win-compat.

I can look into creating an un-minified build, but right now I don't have the time.

@Vinai Vinai changed the title Windows : [ERROR] Command failed Windows Compatibility: [ERROR] Command failed Nov 7, 2018
@rafal-kos
Copy link
Author

rafal-kos commented Nov 7, 2018

OK. There is still the same problem. I had some time to make some debug. So... problem is not directly with path but how the php is processed from the windows cmd.exe. cmd.exe is run when you call child_process.execSync(cmd)

On windows this one will not work :
php -r 'echo json_encode((require "D:\projects\example\magento\app/etc/env.php") ?? []);'
when this one works fine :
php -r "echo json_encode((require 'D:\projects\example\magento\app/etc/env.php') ?? []);"

After changing the command and running bin/cache-clean.js cache was cleaned up 😃

Problem is when I ran bin/cache-clean.js -w. Below the error
[ERROR] Command failed: php -r 'require "D:\projects\example\magento\vendor/autoload.php"; foreach ((new \Magento\Framework\Component\ComponentRegistrar)->getPaths("module") as $m) echo $m.PHP_EOL;'

In this case I suppose that you have to change slightly how the commands are run on windows. I would like to help more but closure is just out of my scope 😄

@Vinai
Copy link
Contributor

Vinai commented Nov 7, 2018

Thanks for the input!
So executed command arguments have to be quoted with double strings.
That sounds possible. I'll see that I get a version ready some time soon that does that.

@Vinai
Copy link
Contributor

Vinai commented Nov 8, 2018

Okay, so I threw away the slash-to-backslash in file system paths conversion code, and instead made command line arguments to php be wrapped in double quotes.
Can you please update the dev-win-compatibility branch and give it another go?

@rafal-kos
Copy link
Author

👍 it works almost perfect but.. still problem with --watch. Below the command

php -d display_errors -r "require 'D:\projects\example\magento/vendor/autoload.php'; foreach ((new \Magento\Framework\Component\ComponentRegistrar)->getPaths('module') as \$m) echo \$m.PHP_EOL;"

and error I am receiving
Parse error: syntax error, unexpected '$m' (T_VARIABLE), expecting identifier (T_STRING) in Command line code on line 1

@Vinai
Copy link
Contributor

Vinai commented Nov 9, 2018

Thanks for trying that out. Interesting.
When I run that exact command on OS X or Linux it works.
Maybe the $ of $m has to be escaped with a different character than \ on windows? Or maybe it doesn't have to be escaped at all?
In my shell it is required so it isn't interpreted as a bash variable that needs to be interpolated into the string.

@Vinai
Copy link
Contributor

Vinai commented Nov 9, 2018

After a bit of googling it seems like it might be the ^ character.
Could you please try running the command?

php -d display_errors -r "require 'D:\projects\example\magento/vendor/autoload.php'; foreach ((new \Magento\Framework\Component\ComponentRegistrar)->getPaths('module') as ^$m) echo ^$m.PHP_EOL;"

@rafal-kos
Copy link
Author

I've got this error then :
Parse error: syntax error, unexpected '^' in Command line code on line 1

This command works fine :
php -d display_errors -r "require 'D:\projects\example\magento/vendor/autoload.php'; foreach ((new \Magento\Framework\Component\ComponentRegistrar)->getPaths('module') as $m) echo $m.PHP_EOL;"

Is there a need for \ or ^?

@Vinai
Copy link
Contributor

Vinai commented Nov 9, 2018

Well, that’s what I’m trying to figure out.
I know the $ needs quoting on unix systems.
Can you try running the command without any quotes for the $ and let me know if that works on windows?

@rafal-kos
Copy link
Author

As I said in my last comment. It works fine without "" and I see list of directories in output.

@Vinai
Copy link
Contributor

Vinai commented Nov 9, 2018

Oh, I didn't see that part, sorry. Thanks for your answer, I'll remove the quoting of the $ on windows.

@Vinai
Copy link
Contributor

Vinai commented Nov 9, 2018

New build available on the win-compatibility branch without quoting of PHP variables in command line arguments on windows.
Hope this solves the issue of executing PHP on windows finally.

@rafal-kos
Copy link
Author

OK. Cleaning speciific type of cache is working fine. Now I am testing "watch" action. For now I few times this kind of issue

Error: ENOENT: no such file or directory, unlink 'D:\projects\example\magento\generated\code\Vendor\Module\Controller\Adminhtml\Artist\Edit\Interceptor.php'
    at Object.fs.unlinkSync (fs.js:1061:18)
    at Jh (D:\projects\example\magento\vendor\mage2tv\magento-cache-clean\bin\cache-clean.js:318:201)
    at D:\projects\example\magento\vendor\mage2tv\magento-cache-clean\bin\cache-clean.js:303:275
    at Xc (D:\projects\example\magento\vendor\mage2tv\magento-cache-clean\bin\cache-clean.js:103:185)
    at Nd.f.ca (D:\projects\example\magento\vendor\mage2tv\magento-cache-clean\bin\cache-clean.js:126:67)
    at eb (D:\projects\example\magento\vendor\mage2tv\magento-cache-clean\bin\cache-clean.js:104:349)
    at og (D:\projects\example\magento\vendor\mage2tv\magento-cache-clean\bin\cache-clean.js:303:238)
    at yk (D:\projects\example\magento\vendor\mage2tv\magento-cache-clean\bin\cache-clean.js:399:271)
    at D:\projects\example\magento\vendor\mage2tv\magento-cache-clean\bin\cache-clean.js:400:101
    at FSWatcher.<anonymous> (D:\projects\example\magento\vendor\mage2tv\magento-cache-clean\bin\cache-clean.js:320:138

After checking the path file was deleted but watcher was stopped and I had to run it again.

I will do more tests next week and probably be back in case of any additional issues.

@Vinai
Copy link
Contributor

Vinai commented Nov 9, 2018

Cool, one step further towards supporting windows 👍
Thanks for your help.
I wonder why the file already was gone by the time fs.unlinkSync is called.
As a reference for myself, maybe this is helpful: https://stackoverflow.com/a/20801823/485589

@Vinai
Copy link
Contributor

Vinai commented Nov 15, 2018

@rafal-kos Any news on this topic by chance? I could wrap the unlink in a check to see if the file still exists.
When does that exception occur? When changing a file?

Vinai added a commit that referenced this issue Nov 18, 2018
On windows the watcher throws exceptions about unlinking non-existent files.
This might fix it...
See #17 (comment)
@Vinai
Copy link
Contributor

Vinai commented Nov 18, 2018

I added regexes that match file paths with backslashes instead of regular slashes, added a check if a file exists before unlinking it, and merged the result into master and published it as release 0.0.25.
It would be cool if you could try how that works for you...

@rafal-kos
Copy link
Author

Sorry for late response but I didn't had time to check it. I have installed latest version from master branch. No error about missing file but I suppose it doesn't work correctly. Example output of command run with options "-w -vv":

Processing D:\projects\example\app\code\Vendor\Artist/view\adminhtml\ui_component\artist_form.xml
Cleaning id(s): ui_component_configuration_data_artist_form
Cache storage  {:backend Cm_Cache_Backend_File, :cache_dir D:\projects\example/var/cache}
Processing D:\projects\example\app\code\Vendor\Artist/view\adminhtml\ui_component
Processing D:\projects\example\app\code\Vendor\Artist/view\adminhtml\ui_component\artist_form.xml
Cleaning id(s): ui_component_configuration_data_artist_form
Cache storage  {:backend Cm_Cache_Backend_File, :cache_dir D:\projects\example/var/cache}
Processing D:\projects\example\app\code\Vendor\Artist/view\adminhtml\ui_component
Processing D:\projects\example\app\code\Vendor\Artist/view\adminhtml\ui_component
Processing D:\projects\example\app\code\Vendor\Artist/view\adminhtml\ui_component\artist_form.xml
Cleaning id(s): ui_component_configuration_data_artist_form
Cache storage  {:backend Cm_Cache_Backend_File, :cache_dir D:\projects\example/var/cache}
Processing D:\projects\example\app\code\Vendor\Artist/view\adminhtml\ui_component
Processing D:\projects\example\app\code\Vendor\Artist/view\adminhtml\ui_component
Processing D:\projects\example\app\code\Vendor\Artist/view\adminhtml\ui_component\artist_form.xml
Cleaning id(s): ui_component_configuration_data_artist_form
Cache storage  {:backend Cm_Cache_Backend_File, :cache_dir D:\projects\example/var/cache}
Processing D:\projects\example\app\code\Vendor\Artist/view\adminhtml\ui_component
Processing D:\projects\example\app\code\Vendor\Artist/view\adminhtml\ui_component
Processing D:\projects\example\app\code\Vendor\Artist/etc\adminhtml\menu.xml
Processing D:\projects\example\app\code\Vendor\Artist/etc\adminhtml
Processing D:\projects\example\app\code\Vendor\Artist/view\adminhtml\ui_component\artist_form.xml
Cleaning id(s): ui_component_configuration_data_artist_form
Cache storage  {:backend Cm_Cache_Backend_File, :cache_dir D:\projects\example/var/cache}
Processing D:\projects\example\app\code\Vendor\Artist/view\adminhtml\ui_component
Processing D:\projects\example\app\code\Vendor\Artist/view\adminhtml\ui_component
Processing D:\projects\example\app\code\Vendor\Artist/view\adminhtml\ui_component\artist_form.xml
Cleaning id(s): ui_component_configuration_data_artist_form
Cache storage  {:backend Cm_Cache_Backend_File, :cache_dir D:\projects\example/var/cache}
Processing D:\projects\example\app\code\Vendor\Artist/view\adminhtml\ui_component

After change in ui component or menu file I see info about processing but cache is not cleared.

For example I am changing title in menu.xml. I see "processing" output but no info about clearing of cache.

@Vinai
Copy link
Contributor

Vinai commented Nov 29, 2018

Thanks for trying out the new version and giving an update @rafal-kos!
In order to be able to work on windows support more effectively I'll add a new trace log level that will give more details when enabled with -vvv.
Also, could you please try editing a di.xml file?
The difference is that editing ui_component files clears a single cache ID, while editing a di.xml file will clear the whole config cache segment.

Thanks for your help.

@Vinai
Copy link
Contributor

Vinai commented Nov 29, 2018

Update to the win-compatibility branch pushed.
When you have a moment, please update with

composer remove --dev mage2tv/magento-cache-clean
composer require --dev mage2tv/magento-cache-clean:dev-win-compatibility

Then check the release matches this:

$ cache-clean.js --version
Release 0.0.27-dev-win-compat sponsored by https://www.mage2.tv

0.0.27-dev-win-compat

If that is true, please run the command with the -w -vvv options to enable trace level logging.

Then edit a ui_component XML file and a di.xml file and post the (probably long) output here in the thread.

Again, thank you for your help, I appreciate you doing that.

@rafal-kos
Copy link
Author

Still the same :(

First I am changing the ui_component XML file. Output :

Watcher initialized (Ctrl-C to quit)
Processing D:\projects\magento\app\code\Vendor\Artist/view\adminhtml\ui_component\artist_form.xml
Cleaning id(s): ui_component_configuration_data_artist_form
Cache storage  {:backend Cm_Cache_Backend_File, :cache_dir D:\projects\magento/var/cache}
Delete cache record if exists: D:\projects\magento/var/cache/mage--3/mage---fa7_UI_COMPONENT_CONFIGURATION_DATA
_ARTIST_FORM

Then some changes in di.xml is done. Output :

Processing D:\projects\magento\app\code\Vendor\Artist/view\adminhtml\ui_component
Processing D:\projects\magento\app\code\Vendor\Artist/view\adminhtml\ui_component
Processing D:\projects\magento\app\code\Vendor\Artist/etc\di.xml
Processing D:\projects\magento\app\code\Vendor\Artist/etc

I don't see any change on form after reloading the page.

@mage2tv mage2tv deleted a comment from JDavidVR Dec 1, 2018
@Vinai
Copy link
Contributor

Vinai commented Dec 1, 2018

@rafal-kos Thanks again for your help and your patience.

The paths still contain forward slashes. I'll focus next on making them consistent - then the regex to fingerprint the file names should work more reliable.

@Vinai
Copy link
Contributor

Vinai commented Dec 1, 2018

I've updated the win-compatibility branch accordingly.
The release string now is 0.0.28-dev-win-compat

For reference, to install the current version of the branch, please use:

composer remove --dev mage2tv/magento-cache-clean
composer require --dev mage2tv/magento-cache-clean:dev-win-compatibility

@rafal-kos Can you please try it when you get a chance and let me know if there is some progress?

Thank you!

@Vinai Vinai added the help wanted Extra attention is needed label Jan 9, 2019
@Vinai Vinai added the windows label Apr 1, 2019
@Vinai
Copy link
Contributor

Vinai commented Apr 4, 2019

The cache-clean.js utility seems to now work on windows (since release 0.0.37), at least under some circumstances.
Reference issue #32

It would be great if I could get confirmation from others using a windows based development environment!

@rafal-kos
Copy link
Author

I'm back to this topic. I have installed latest version. Still some issues. For example I have made some changes in ui component xml (artist_listing.xml). In output I see this :

Cleaning id(s): ui_component_configuration_data_artist_listing

but after reload I still see old content. In var/cache/mage--a/mage---608_UI_COMPONENT_CONFIGURATION_DATA_ARTIST_LISTING file is still existing.

Also changes in etc/di.xml or etc/adminhtml/system.xml are not reloading the cache. Nothing in output.

@Vinai
Copy link
Contributor

Vinai commented Apr 23, 2019

Hi @rafal-kos, I'm happy you are back on this topic, welcome back!
When you say "the latest version", which version is this?
Can you please also post your cache related configuration in app/etc/env.php?
Thanks!

@rafal-kos
Copy link
Author

@Vinai ./vendor/bin/cache-clean.js -v gives me this output :

Release 0.0.37 sponsored by https://www.mage2.tv

In app/etc/env.php I have nothing regarding the cache. As I understand magento in this case is using file system for cache storage. I can check with db for example just to see if this is related for file system.

@Vinai
Copy link
Contributor

Vinai commented Apr 23, 2019

No, you are right - no cache configuration in app/etc/env.php means the file system cache storage is used.

@Vinai
Copy link
Contributor

Vinai commented Apr 23, 2019

Okay, next question.
If you run the watcher with the -vv flag to enable debug output, there is a line that reads something like: Calculated default cache ID prefix <id-prefix> from <path>.

Can you please let me know what the <path> is in your case?
Thanks!

@rafal-kos
Copy link
Author

Example output :

Magento dir D:\projects\projekty\project_name\magento
Flushing all caches
Using :default cache_backend
Calculated default cache ID prefix f78_ from D:\projects\projekty\project_name\magentoapp/etc/
Cache storage  {:backend Cm_Cache_Backend_File, :cache_dir D:/projects/projekty/project_name/magento/var/cache, :id_prefix f78_}
Cleaning dir D:/projects/projekty/project_name/magento/var/cache/
Using :page_cache cache backend
Cache storage  {:backend Cm_Cache_Backend_File, :cache_dir D:/projects/projekty/project_name/magento/var/page_cache, :id_prefix f78_}
Cleaning dir D:/projects/projekty/project_name/magento/var/page_cache/

This path D:\projects\projekty\project_name\magentoapp/etc/ looks strange. Maybe some issue here?

@Vinai
Copy link
Contributor

Vinai commented Apr 23, 2019

It does indeed. There is at least one bug in there that’s already fixed.
Could you please upgrade to release 0.0.40 and check again? At least the missing directory separator between magento and app should be there then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed windows
Projects
None yet
Development

No branches or pull requests

2 participants