astorm / pestle

A collection of command line scripts for Magento 2 code generation, and a PHP module system for organizing command line scripts.
MIT License
533 stars 101 forks source link

Generating files causing error. Magento 2.3.3 #506

Closed mumar786 closed 4 years ago

mumar786 commented 5 years ago

php pestle.phar generate_module Pulsestorm JavascriptCssExample 0.1.0

Comes up with the following error: PHP Fatal error: Uncaught Error: Class 'Pulsestorm\Pestle\Config\Exception' not found in phar://C:/xampp/htdocs/ecommerce_test/pestle.phar/modules/pulsestorm/pestle/config/module.php:52 Stack trace:

0 phar://C:/xampp/htdocs/ecommerce_test/pestle.phar/modules/pulsestorm/pestle/config/module.php(66): Pulsestorm\Pestle\Config\getOrSetConfigBase()

1 phar://C:/xampp/htdocs/ecommerce_test/pestle.phar/modules/pulsestorm/pestle/config/module.php(34): Pulsestorm\Pestle\Config\getPathConfig('package-folders')

2 [internal function]: Pulsestorm\Pestle\Config\loadConfigFile('package-folders')

3 phar://C:/xampp/htdocs/ecommerce_test/pestle.phar/modules/pulsestorm/pestle/config/module.php(18): call_user_func('Pulsestorm\Pest...', 'package-folders')

4 [internal function]: Pulsestorm\Pestle\Config\loadConfig('package-folders')

5 C:\tmp\pestle_cache\2d27f575ea4837c003f8467c72c32131\reflection-strategy\813ea2af6b985b27c8cb26ffbcf461c5.php(7): ReflectionFunction->invokeArgs(Array)

6 phar://C:/xampp/htdocs/ecommerce_test/pestle.phar/modul in phar://C:/xampp/htdocs/ecommerce_test/pestle.phar/modules/pulsestorm/pestle/config/module.php on line 52

Fatal error: Uncaught Error: Class 'Pulsestorm\Pestle\Config\Exception' not found in phar://C:/xampp/htdocs/ecommerce_test/pestle.phar/modules/pulsestorm/pestle/config/module.php:52 Stack trace:

0 phar://C:/xampp/htdocs/ecommerce_test/pestle.phar/modules/pulsestorm/pestle/config/module.php(66): Pulsestorm\Pestle\Config\getOrSetConfigBase()

1 phar://C:/xampp/htdocs/ecommerce_test/pestle.phar/modules/pulsestorm/pestle/config/module.php(34): Pulsestorm\Pestle\Config\getPathConfig('package-folders')

2 [internal function]: Pulsestorm\Pestle\Config\loadConfigFile('package-folders')

3 phar://C:/xampp/htdocs/ecommerce_test/pestle.phar/modules/pulsestorm/pestle/config/module.php(18): call_user_func('Pulsestorm\Pest...', 'package-folders')

4 [internal function]: Pulsestorm\Pestle\Config\loadConfig('package-folders')

5 C:\tmp\pestle_cache\2d27f575ea4837c003f8467c72c32131\reflection-strategy\813ea2af6b985b27c8cb26ffbcf461c5.php(7): ReflectionFunction->invokeArgs(Array)

6 phar://C:/xampp/htdocs/ecommerce_test/pestle.phar/modul in phar://C:/xampp/htdocs/ecommerce_test/pestle.phar/modules/pulsestorm/pestle/config/module.php on line 52

Any idea what's causing this?

astorm commented 5 years ago

Thanks for giving Pestle a try @mumar786 -- sorry to hear you ran into some trouble. If you don't mind, I have a two standard-ish questions I'd like to ask that will help us get to the bottom of what's happening

  1. Have you ever successfully run a pestle command, or is this your first time giving it a try?

  2. It looks like you're running this on a Windows machine -- do you know how you're running PHP on Windows? I'm asking this because there's multiple ways of running PHP on Windows (Native Windows Binaries, via the Linux/Ubuntu subsystem, Cygwin, etc)

If you can answer the above, we might be able to reproduce your problem and then figure out what's going on.

Also, for what it's worth, pestle is generally developed on linux/unix -- native PHP on windows isn't something we spend a lot of time on (mainly because I don't use windows for web development and no one else has stepped up to take that on). That fastest way to get pestle working would be to start working in a linux/unix environment.

That said -- we'd still love some answers to the above to see if there's a quickfix we could adopt.

mumar786 commented 5 years ago
  1. Yes, this is my first time trying a pestle command. (Tried the generate_full_module command as well but it came up with the exact same errors).
  2. I'm pretty new at programming, not sure how to check how PHP is being run, but I'm using a standard windows 10 home installation and using a local server XAMPP (for Windows 10) which has PHP 7.3 Installed.

Out of curiosity, do Linux/Windows files have different structures? Or is it the command line that's different?

astorm commented 5 years ago

Thanks for that information -- "XAMPP" is exactly what I was looking for when I asked you how you were running PHP. This week I'll try to reproduce the problem XAMPP installed PHP, and then determine if it's something I can fix easily/without-to-much-investment.

Out of curiosity, do Linux/Windows files have different structures? Or is it the command line that's different?

Since you're pretty new to programming I'm not sure what level to answer this question at, but no, linux files and windows files have 99.9% the same structure. The .1% is the characters used to end a line -- but most modern text editors take care of this for you.

The problem is, as you suspected, the command line. The windows command line (or windows shell) uses a syntax that's very different from the unix command line (or unix shell, or bash shell ) -- the syntax you use to access files and paths is different. PHP does some work to normalize this but it's far from perfect, and that's where I expect the problem is.

mumar786 commented 5 years ago

Ah amazing, that makes a lot more sense now. Thanks!

andyrz commented 4 years ago

Hello, Did you ever take a look at this issue? I am using Windows 10 and have tried using the Windows default cmd utility and also have tried Cygwin with no success.

Fatal error: Uncaught Error: Class 'Pulsestorm\Pestle\Config\Exception' not foun d in phar://C:/wamp64/www/mage/pestle.phar/modules/pulsestorm/pestle/config/modu le.php:52 Stack trace:

0 phar://C:/wamp64/www/mage/pestle.phar/modules/pulsestorm/pestle/config/module

.php(66): Pulsestorm\Pestle\Config\getOrSetConfigBase()

1 phar://C:/wamp64/www/mage/pestle.phar/modules/pulsestorm/pestle/config/module

.php(34): Pulsestorm\Pestle\Config\getPathConfig('package-folders')

2 [internal function]: Pulsestorm\Pestle\Config\loadConfigFile('package-folders

')

3 phar://C:/wamp64/www/mage/pestle.phar/modules/pulsestorm/pestle/config/module

.php(18): call_user_func('Pulsestorm\Pest...', 'package-folders')

4 [internal function]: Pulsestorm\Pestle\Config\loadConfig('package-folders')

5 C:\tmp\pestle_cache\2d27f575ea4837c003f8467c72c32131\reflection-strategy\813e

a2af6b985b27c8cb26ffbcf461c5.php(7): ReflectionFunction->invokeArgs(Array)

6 phar://C:/wamp64/www/mage/pestle.phar/modules/pulsestorm/magento2/cli/library

/module.php(91): loadConfi in phar://C:/wamp64/www/mage/pestle.phar/modules/puls estorm/pestle/config/module.php on line 52

astorm commented 4 years ago

@andyrz Thank your for writing. Unfortunately, I have not had a chance to look too deeply into this. I'm unsurprising that this doesn't work from a windows console. I'm a little surprised it doesn't work with Cygwin. My memory of Cygwin is it's a linux shell with linux filepaths and everything should work.

We're also being hit with a double whammy with this one, as it looks like the module in question has a bug where it's trying to throw a local Exception instead of the global \Exception.

@andyrz Is this something that just started happening? Or did you download pestle for the first time and it happened? Also -- there's a /tmp/pestle_cache folder that can sometimes get stale when you run the same phar from different enviornments -- can you try deleting it and seeing if that helps?

andyrz commented 4 years ago

@astorm Thank you for responding. I greatly appreciate you spending the time here.

This is the first time I've attempted to use Pestle and it never worked on this particular machine(Windows 10). I cleared the cache under C:\tmp\pestle_cache but still received the same error. I found a work around that allowed me to move forward. I installed the Ubuntu Linux subsystem which gives Bash access to the Windows file system. I learned that Bash doesn't access the Windows env variables so I installed PHP 7.2 and the required XML extension(apt-get install php7.2-xml) in order to run Pestle. This is a valid work around for me and I look forward to using Pestle.

astorm commented 4 years ago

@andyrz Could you let us know the exact invocations you were using when you ran into the above error? I got an old windows laptop setup and was able to make pestle run

C:\Users\alanstorm\github\astorm\pestle>c:\MAMP\bin\php\php7.1.20\php pestle.phar list

Knowing the exact command you were trying to run and how you invoked it would help us get to the bottom of this.

andyrz commented 4 years ago

@astorm I am able to run the following without issue:

PS C:\wamp64\www\mage> php pestle.phar list PS C:\wamp64\www\mage> php pestle.phar magento2:base-dir C:\wamp64\www\mage

but cannot create a module:

PS C:\wamp64\www\mage> php pestle.phar generate_module Vendor Namespace? (Pulsestorm)] Azaluski Module Name? (Testbed)] Testbed Version? (0.0.1)] 0.0.1

Fatal error: Uncaught Error: Class 'Pulsestorm\Pestle\Config\Exception' not found in phar://C:/wamp64/www/mage/pestle.phar/modules/pulsestorm/pestle/config/module.php:52 Stack trace:

0 phar://C:/wamp64/www/mage/pestle.phar/modules/pulsestorm/pestle/config/module.php(66): Pulsestorm\Pestle\Config\getOrSetConfigBase()

1 phar://C:/wamp64/www/mage/pestle.phar/modules/pulsestorm/pestle/config/module.php(34): Pulsestorm\Pestle\Config\getPathConfig('package-folders')

2 [internal function]: Pulsestorm\Pestle\Config\loadConfigFile('package-folders')

3 phar://C:/wamp64/www/mage/pestle.phar/modules/pulsestorm/pestle/config/module.php(18): call_user_func('Pulsestorm\Pest...', 'package-folders')

4 [internal function]: Pulsestorm\Pestle\Config\loadConfig('package-folders')

5 C:\tmp\pestle_cache\2d27f575ea4837c003f8467c72c32131\reflection-strategy\813ea2af6b985b27c8cb26ffbcf461c5.php(7): ReflectionFunction->invokeArgs(Array)

6 phar://C:/wamp64/www/mage/pestle.phar/modules/pulsestorm/magento2/cli/library/module.php(91): loadConfi in phar://C:/wamp64/www/mage/pestle.phar/modules/pulsestorm/pestle/config/module.php on line 52

Here is my php info:

PS C:\wamp64\www\mage> php -i phpinfo() PHP Version => 7.2.18

System => Windows NT NOPE-NOT-TODAY 10.0 build 18362 (Windows 10) AMD64 Build Date => Apr 30 2019 23:25:56 Compiler => MSVC15 (Visual C++ 2017) Architecture => x64 Configure Command => cscript /nologo configure.js "--enable-snapshot-build" "--enable-debug-pack" "--with-pdo-oci=c:\php-snap-build\deps_aux\oracle\x64\instantclient_12_1\sdk,shared" "--with-oci8-12c=c:\php-snap-build\deps_aux\oracle\x64\instantclient_12_1\sdk,shared" "--enable-object-out-dir=../obj/" "--enable-com-dotnet=shared" "--without-analyzer" "--with-pgo" Server API => Command Line Interface Virtual Directory Support => enabled Configuration File (php.ini) Path => C:\WINDOWS Loaded Configuration File => C:\wamp64\bin\php\php7.2.18\php.ini Scan this dir for additional .ini files => (none) Additional .ini files parsed => (none) PHP API => 20170718 PHP Extension => 20170718 Zend Extension => 320170718 Zend Extension Build => API320170718,TS,VC15 PHP Extension Build => API20170718,TS,VC15 Debug Build => no Thread Safety => enabled Zend Signal Handling => disabled Zend Memory Manager => enabled Zend Multibyte Support => provided by mbstring IPv6 Support => enabled DTrace Support => disabled

Registered PHP Streams => php, file, glob, data, http, ftp, zip, compress.zlib, compress.bzip2, https, ftps, phar Registered Stream Socket Transports => tcp, udp, ssl, tls, tlsv1.0, tlsv1.1, tlsv1.2 Registered Stream Filters => convert.iconv., string.rot13, string.toupper, string.tolower, string.strip_tags, convert., consumed, dechunk, zlib., bzip2.

This program makes use of the Zend Scripting Language Engine: Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

astorm commented 4 years ago

Thanks you @andyrz, that's let us get to the bottom of this. It looks like the problem is right here

https://github.com/astorm/pestle/blob/master/modules/pulsestorm/pestle/config/module.php#L50

In order to determine your home directory, pestle uses the echo ~ command. This works in most operating system, but it doesn't work in native Windows. We'll need to replace that with some conditional code that does something like

echo %HOMEPATH%

if you're in a windows environment. Thanks for bringing this to our attention and for providing the reproduction steps -- without that we wouldn't have been able to identify the root problem.

We are unsure when we'll be able to get a release going for this, but if anyone wanted to submit a PR to fix things it would definitely help move things along.

astorm commented 4 years ago

PR merged, should go out in the next release: https://github.com/astorm/pestle/pull/512