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

Error accessing box from Windows (getenv('ANSICON') returns boolean) #1002

Closed
andrey-helldar opened this issue Jun 22, 2023 · 7 comments
Closed

Comments

@andrey-helldar
Copy link

andrey-helldar commented Jun 22, 2023

Bug report

Question Answer
Box version 4.3.8
PHP version 8.1.20
Platform with version Windows
Github Repo https://github.com/TheDragonCode/codestyler

I am using Laravel Zero which contains the Box binary.

Yesterday they updated the framework version with Box file version 4.3.8. Previously version 4.2.0 was used.

There are no problems with version 4.2.0, but in 4.3.8 they appeared and manifest themselves as follows:

  1. Compilation of the phar file happens without errors, BUT:
  2. When I try to call a phar file from the console, I get an error;
  3. When I try to get the box version of the file, I get the same error.

With all this, the error is displayed only under Windows. There are no problems when running inside Ubuntu.

box.json.dist
{
   "chmod": "0755",
   "directories": [
       "app",
       "bootstrap",
       "config",
       "resources",
       "vendor",
       "modules/laravel/pint/app",
       "modules/laravel/pint/resources/views"
   ],
   "files": [
       ".editorconfig",
       "composer.json",
       "The_Dragon_Code_phpStorm.xml"
   ],
   "exclude-composer-files": false,
   "exclude-dev-files": false,
   "compression": "GZ",
   "compactors": [
       "KevinGH\\Box\\Compactor\\Php",
       "KevinGH\\Box\\Compactor\\Json"
   ]
}
Output
$ ./vendor/laravel-zero/framework/bin/box --version
PHP Fatal error:  Uncaught TypeError: trim(): Argument #1 ($string) must be of type string, bool given in phar://D:/domains/dragon-code/codestyler/vendor/laravel-zero/framework/bin/box/.box/src/Terminal.php:60
Stack trace:
#0 phar://D:/domains/dragon-code/codestyler/vendor/laravel-zero/framework/bin/box/.box/src/Terminal.php(60): trim(false)
#1 phar://D:/domains/dragon-code/codestyler/vendor/laravel-zero/framework/bin/box/.box/src/Terminal.php(31): HumbugBox436\KevinGH\RequirementChecker\Terminal::initDimensions()
#2 phar://D:/domains/dragon-code/codestyler/vendor/laravel-zero/framework/bin/box/.box/src/Printer.php(28): HumbugBox436\KevinGH\RequirementChecker\Terminal->getWidth()
#3 phar://D:/domains/dragon-code/codestyler/vendor/laravel-zero/framework/bin/box/.box/src/Checker.php(17): HumbugBox436\KevinGH\RequirementChecker\Printer->__construct(32, true)
#4 phar://D:/domains/dragon-code/codestyler/vendor/laravel-zero/framework/bin/box/.box/bin/check-requirements.php(22): HumbugBox436\KevinGH\RequirementChecker\Checker::checkRequirements()
#5 D:\domains\dragon-code\codestyler\vendor\laravel-zero\framework\bin\box(16): require('phar://D:/domai...')
#6 {main}
 thrown in phar://D:/domains/dragon-code/codestyler/vendor/laravel-zero/framework/bin/box/.box/src/Terminal.php on line 60

Fatal error: Uncaught TypeError: trim(): Argument #1 ($string) must be of type string, bool given in phar://D:/domains/dragon-code/codestyler/vendor/laravel-zero/framework/bin/box/.box/src/Terminal.php:60
Stack trace:
#0 phar://D:/domains/dragon-code/codestyler/vendor/laravel-zero/framework/bin/box/.box/src/Terminal.php(60): trim(false)
#1 phar://D:/domains/dragon-code/codestyler/vendor/laravel-zero/framework/bin/box/.box/src/Terminal.php(31): HumbugBox436\KevinGH\RequirementChecker\Terminal::initDimensions()
#2 phar://D:/domains/dragon-code/codestyler/vendor/laravel-zero/framework/bin/box/.box/src/Printer.php(28): HumbugBox436\KevinGH\RequirementChecker\Terminal->getWidth()
#3 phar://D:/domains/dragon-code/codestyler/vendor/laravel-zero/framework/bin/box/.box/src/Checker.php(17): HumbugBox436\KevinGH\RequirementChecker\Printer->__construct(32, true)
#4 phar://D:/domains/dragon-code/codestyler/vendor/laravel-zero/framework/bin/box/.box/bin/check-requirements.php(22): HumbugBox436\KevinGH\RequirementChecker\Checker::checkRequirements()
#5 D:\domains\dragon-code\codestyler\vendor\laravel-zero\framework\bin\box(16): require('phar://D:/domai...')
#6 {main}
 thrown in phar://D:/domains/dragon-code/codestyler/vendor/laravel-zero/framework/bin/box/.box/src/Terminal.php on line 60

On execution, the error points to the code trim(getenv('ANSICON'))

I also downloaded the phar file from the latest release and also got an error:

Output
$ ./box.phar --version
PHP Fatal error:  Uncaught TypeError: trim(): Argument #1 ($string) must be of type string, bool given in phar://D:/domains/box.phar/.box/src/Terminal.php:60
Stack trace:
#0 phar://D:/domains/box.phar/.box/src/Terminal.php(60): trim(false)
#1 phar://D:/domains/box.phar/.box/src/Terminal.php(31): HumbugBox436\KevinGH\RequirementChecker\Terminal::initDimensions()
#2 phar://D:/domains/box.phar/.box/src/Printer.php(28): HumbugBox436\KevinGH\RequirementChecker\Terminal->getWidth()
#3 phar://D:/domains/box.phar/.box/src/Checker.php(17): HumbugBox436\KevinGH\RequirementChecker\Printer->__construct(32, true)
#4 phar://D:/domains/box.phar/.box/bin/check-requirements.php(22): HumbugBox436\KevinGH\RequirementChecker\Checker::checkRequirements()
#5 D:\domains\box.phar(16): require('phar://D:/domai...')
#6 {main}
 thrown in phar://D:/domains/box.phar/.box/src/Terminal.php on line 60

Fatal error: Uncaught TypeError: trim(): Argument #1 ($string) must be of type string, bool given in phar://D:/domains/box.phar/.box/src/Terminal.php:60
Stack trace:
#0 phar://D:/domains/box.phar/.box/src/Terminal.php(60): trim(false)
#1 phar://D:/domains/box.phar/.box/src/Terminal.php(31): HumbugBox436\KevinGH\RequirementChecker\Terminal::initDimensions()
#2 phar://D:/domains/box.phar/.box/src/Printer.php(28): HumbugBox436\KevinGH\RequirementChecker\Terminal->getWidth()
#3 phar://D:/domains/box.phar/.box/src/Checker.php(17): HumbugBox436\KevinGH\RequirementChecker\Printer->__construct(32, true)
#4 phar://D:/domains/box.phar/.box/bin/check-requirements.php(22): HumbugBox436\KevinGH\RequirementChecker\Checker::checkRequirements()
#5 D:\domains\box.phar(16): require('phar://D:/domai...')
#6 {main}
 thrown in phar://D:/domains/box.phar/.box/src/Terminal.php on line 60
@owenvoke
Copy link
Contributor

Hey @andrey-helldar, I think this is due to the change to strict types in Box 3.8, which has led to the false return type from getenv() no longer being cast to an empty string.

This should be fixable by basically falling back to an empty string when getenv() returns null. Which would replicate the previous functionality.

@andrey-helldar
Copy link
Author

Yes, but I'm not using the environment settings and the .env file doesn't exist.

In addition, if we try to execute a simple variable lookup code, we get the following:

$ php -r "var_dump(getenv('ANSICON'));"
bool(false)

@owenvoke
Copy link
Contributor

What I'm meaning is, this is code from Box (not LZ). It doesn't matter whether you are using the Env component, it will still try and run this code as part of the environment checker.

As you can see from your example code, running it returns false, and therefore this will fail when passed to trim() as it's expecting a string. 👍🏻

As a temporary workaround, you could disable the requirements checker for your Phar by adding "check-requirements": false to your box.json (or running with BOX_REQUIREMENT_CHECKER=0 set in your env).

However, to fix this, it will require a change in Box so that this strict type check doesn't fail.

@owenvoke
Copy link
Contributor

@andrey-helldar, just to mention, this will be resolved once #999 is merged and released. 👍🏻

@andrey-helldar
Copy link
Author

@owenvoke, wow. I was trying to find issues or PRs for my issue, but searched for ansi. Sorry 😅

underdpt referenced this issue in laravel-zero/framework Jun 30, 2023
@8ctopus
Copy link

8ctopus commented Jul 12, 2023

same issue for me on Windows, reverting to 4.2.0 fixes it.

@theofidry
Copy link
Member

#999 has been merged and 4.4.0 release. If there is still an issue please comment on it or open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants