aisingapore / TagUI

Free RPA tool by AI Singapore
Apache License 2.0
5.6k stars 580 forks source link

Fixed PHP error "Uncaught TypeError: count()" with newer macOS versions - done #1137

Closed kensoh closed 2 years ago

kensoh commented 2 years ago

There are couple of users who reported issues with PHP in this thread https://github.com/kelaberetiv/TagUI/issues/1136

Raising an issue to check on this, which might be an OS-wide change for new macOS version 12 (Monterey)

kensoh commented 2 years ago

I'm running 10.15.7 now on my Mac laptop

kensoh commented 2 years ago

If you are a Mac user and you are experiencing issues related to PHP, please do share here!

kensoh commented 2 years ago

Root cause is PHP has been removed from macOS Monterey release - https://www.techgenyz.com/2021/06/18/macos-12-monterey-update-built-in-php

Solution is to install PHP manually, until this can be automated (I don't think so need password to run homebrew) or co-packaged. Below will install Homebrew package manager for macOS and then install PHP which TagUI requires to run.

Run the following line by line to install PHP on your Mac computer -

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install php
lookang commented 2 years ago

Good! Thanks for the solution. Everything works except a strange flow causes an error.

the flow is emailsearch3.tag https://github.com/lookang/TagUI/blob/main/login/emailsearch3.tag

output error is PHP Warning: Undefined array key 2 in /Users/lookang/Desktop/tagui/src/tagui_parse.php on line 1123 PHP Warning: Undefined array key 2 in /Users/lookang/Desktop/tagui/src/tagui_parse.php on line 1123

Warning: Undefined array key 2 in /Users/lookang/Desktop/tagui/src/tagui_parse.php on line 1123

Warning: Undefined array key 2 in /Users/lookang/Desktop/tagui/src/tagui_parse.php on line 1123 PHP Warning: Undefined array key 2 in /Users/lookang/Desktop/tagui/src/tagui_parse.php on line 1123 PHP Warning: Undefined array key 2 in /Users/lookang/Desktop/tagui/src/tagui_parse.php on line 1123

Warning: Undefined array key 2 in /Users/lookang/Desktop/tagui/src/tagui_parse.php on line 1123

Warning: Undefined array key 2 in /Users/lookang/Desktop/tagui/src/tagui_parse.php on line 1123 PHP Warning: Undefined array key 2 in /Users/lookang/Desktop/tagui/src/tagui_parse.php on line 1123

Warning: Undefined array key 2 in /Users/lookang/Desktop/tagui/src/tagui_parse.php on line 1123 PHP Warning: Undefined array key 2 in /Users/lookang/Desktop/tagui/src/tagui_parse.php on line 1123

Warning: Undefined array key 2 in /Users/lookang/Desktop/tagui/src/tagui_parse.php on line 1123 ERROR - automation aborted due to above

kensoh commented 2 years ago

Thanks @lookang for catching this bug! As debugged on the Zoom call, above error is introduced in newer Mac when PHP has to be manually installed. In newer PHP versions, there is stricter error handling and above warning message will be shown. The solution that we applied just now on the call is now in TagUI v6.101. You can skip the update because the fix is the same as what we did on your laptop just now.

kensoh commented 2 years ago

Adding on additional input that Tommi from aito.ai runs into below error message when running TagUI on Mac newer PHP -

PHP Fatal error:  Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, bool given in /Users/tommi/Code/tagui/src/tagui_parse.php:35

\ The offending line of code is below (line 35 in tagui_parse.php), this probably needs changing to work with newer PHP -

if (@count($repo_data[$repo_count]) == 0) die("ERROR - empty row found in " . 'tagui_local.csv' . "\n");
tonnitommi commented 2 years ago

running TagUI on Mac newer PHP

Versions for the above were: TagUI: v6.101 MacOS: Monterey 12.0.1 (21A559) PHP: PHP 8.1.0 (cli) (built: Nov 28 2021 01:44:44)

delegate-it commented 2 years ago

Adding on additional input that Tommi from aito.ai runs into below error message when running TagUI on Mac newer PHP -

PHP Fatal error:  Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, bool given in /Users/tommi/Code/tagui/src/tagui_parse.php:35

The offending line of code is below (line 35 in tagui_parse.php), this probably needs changing to work with newer PHP -

if (@count($repo_data[$repo_count]) == 0) die("ERROR - empty row found in " . 'tagui_local.csv' . "\n");

Did you change the above line. I am also facing this issue on a Mac Mini M1 Monterey. PHP version is 8.1.1 mac OS Monterey 12.0.1 tagui v6.46

kensoh commented 2 years ago

Hi @delegate-it that line has not been changed yet, I'll have to upgrade my Mac some time soon, before testing on PHP 8.

In the meantime, can you try deleting or moving away any .csv file in the folder of your RPA .tag file? This will avoid running the execution through that line of code. Sorry for the inconvenience! I'm hesitant to upgrade my Mac for time being, in case there is unexpected downtime for work.

delegate-it commented 2 years ago

Hi @delegate-it that line has not been changed yet, I'll have to upgrade my Mac some time soon, before testing on PHP 8.

In the meantime, can you try deleting or moving away any .csv file in the folder of your RPA .tag file? This will avoid running the execution through that line of code. Sorry for the inconvenience! I'm hesitant to upgrade my Mac for time being, in case there is unexpected downtime for work.

Thank you Ken. I will do the above and will let you know.

kensoh commented 2 years ago

Thanks @delegate-it I hope to upgrade my Mac and be able to test this new PHP version in February, when I've cleared up some committed deliveries and not that worried of downtime after upgrading to new Mac version.

philyeo commented 2 years ago

I am having the same error on my Mac OS monterey v12.1

✘ philipyeo@Philips-MBP  ~  tagui ~/tagui/flows/samples/1_google.tag PHP Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, bool given in /Users/philipyeo/TagUI/src/tagui_parse.php:35 Stack trace:

0 {main}

thrown in /Users/philipyeo/TagUI/src/tagui_parse.php on line 35

Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, bool given in /Users/philipyeo/TagUI/src/tagui_parse.php:35 Stack trace:

0 {main}

thrown in /Users/philipyeo/TagUI/src/tagui_parse.php on line 35 ERROR - automation aborted due to above

kensoh commented 2 years ago

Hi @philyeo thanks for adding on your inputs!

Can you type the following in your terminal and let me know what comes back?

I'm holding off upgrading my Mac to replicate this, in case it brings unexpected downtime for work.

But I'll try to see if I can install PHP separately to try to fix this issue. I suspect issue due to newer PHP, after users have to install PHP on their own, when newer Mac removed PHP from the OS.

php -v
philyeo commented 2 years ago

Hi @philyeo thanks for adding on your inputs!

Can you type the following in your terminal and let me know what comes back?

I'm holding off upgrading my Mac to replicate this, in case it brings unexpected downtime for work.

But I'll try to see if I can install PHP separately to try to fix this issue. I suspect issue due to newer PHP, after users have to install PHP on their own, when newer Mac removed PHP from the OS.

php -v

Thanks for your response @kensoh

its v8.1.1

ewan-chalmers commented 2 years ago

I also have this problem with new install of tagui on Mac Monterey with php v8.1.1

For example

$ tagui ~/.tagui/flows/samples/1_google.tag 
PHP Fatal error:  Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, bool given in /Users/echalmer/.tagui/src/tagui_parse.php:35
Stack trace:
#0 {main}
  thrown in /Users/echalmer/.tagui/src/tagui_parse.php on line 35

Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, bool given in /Users/echalmer/.tagui/src/tagui_parse.php:35
Stack trace:
#0 {main}
  thrown in /Users/echalmer/.tagui/src/tagui_parse.php on line 35
ERROR - automation aborted due to above

I was able to get past the error by replacing every instance of @count($ with @count((array)$ in tagui_parse.php

sed -i '' 's/\@count(\$/\@count((array)\$/' ~/.tagui/src/tagui_parse.php
kensoh commented 2 years ago

Thanks @philyeo and @ewan-chalmers for your inputs and solution! I'm looking into this now and will see if using @ewan-chalmers's solution directly is ok to commit to master. Ideally, I hope the fix will be out today, or latest tomorrow.

philyeo commented 2 years ago

Thanks @philyeo and @ewan-chalmers for your inputs and solution! I'm looking into this now and will see if using @ewan-chalmers's solution directly is ok to commit to master. Ideally, I hope the fix will be out today, or latest tomorrow.

I followed @ewan-chalmers's solution and it worked but I have another issue which is

philipyeo@Philips-MBP  ~/TagUI   master ±  tagui ~/tagui/flows/samples/1_google.tag /usr/local/bin/tagui: line 410: /usr/local/bin/casperjs: No such file or directory

I noticed that you had another ticket with the same issue raised by someone else.

kensoh commented 2 years ago

Thanks Guys! This is now fixed in v6.106. Note that newer MacOS users will still need to run below lines to install PHP -

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install php

If you are using TagUI v6.46 and above, you can get this update with tagui update command or MS Word plug-in Update TagUI button. If not, you can get TagUI v6.46 from this installation page before performing the update. For list of changes since TagUI v6.46 release in mid-June 2021, visit this link (also found at TagUI installation page).

philyeo commented 2 years ago

OK, got rid of the tagui dir which i actually git clone and just donwloaded the copy from https://github.com/kelaberetiv/TagUI/releases/download/v6.46.0/TagUI_macOS.zip unpack and update. than ran google sample and it worked!

kensoh commented 2 years ago

Oh great, thanks Philip! Also copying @tonnitommi on this fix.

Thanks to @ewan-chalmers on your solution. This seems to be the recommended way by other PHP users as well, and I have applied this (array) fix to 4 files in TagUI codebase. tagui_parse.php, tagui_report.php. transpose.php, translate.php.

kensoh commented 2 years ago

Hi @kriskcandy, see if the following works for you?

I'm copying @ruthtxh, I've left AI Singapore, she is continuing on the project and can support you further.

  1. Follow the setup instructions here for Mac. Be sure to change your_tagui_path to your actual location where you unzipped TagUI - https://tagui.readthedocs.io/en/latest/setup.html#macos-linux

  2. After following above steps, type tagui update to grab the latest version of TagUI, which would fix the issue with the PHP error message

kensoh commented 2 years ago

Closing since this change has made its way into the latest packaged release.

strategyideas commented 9 months ago

I am getting an error on Mac OS Monterey. PHP Deprecated: Creation of dynamic property WebSocket\Client::$options is deprecated in /Users/XXXXXXX/Desktop/tagui/src/ws/Client.php on line 25 @kensoh would there be a fix for this?

kensoh commented 9 months ago

@strategyideas can you type php -v to see what is your PHP version? May need to use an older PHP version as workaround -

RPA:~ kensoh$ php -v PHP 8.1.1 (cli) (built: Jan 8 2022 08:29:30) (NTS) Copyright (c) The PHP Group Zend Engine v4.1.1, Copyright (c) Zend Technologies with Zend OPcache v8.1.1, Copyright (c), by Zend Technologies