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

Exit code suggestion - to discuss and review whether to add exit code #731

Closed
muratcim opened this issue Feb 15, 2020 · 9 comments
Closed
Labels

Comments

@muratcim
Copy link

muratcim commented Feb 15, 2020

Hi @kensoh

Exit code returns 0 by default when there is no syntax problem in a code.My suggestion is when exit code is different from 0 when an error is received in the project.Because when a cron job or windows task scheduler is defined, a different value than exit code 0 can be warned.
For this I have added the following code in the tagui.cmd file.

for /f "tokens=*" %%a in (%flow_file%.log) do set "line=%%a"
echo "%line%"|findstr /i /c:"ERROR" >nul
if errorlevel 1 (
 set tagui_error_code=0
) else (
 set tagui_error_code=1
)
@lelesrc
Copy link

lelesrc commented Feb 15, 2020

Similar problem here: my tagui script is launched by an external process and I need to monitor if any error happened during the automation (for example if wrong credentials are provided). Like this:

if !present('LOGOUT')
{
  echo 'error: credentials are not valid ' + username
  this.exit(1)
}

I tried using in my script this.exit(1) and also setting exitCode = 1 before the exit command, but I still have an exit code 0 when i call echo $? from command line.

btw, this also happens when there's an error in the script (for example read can't find a path). The exit code is always 0.

Am I missing something? Is there a way to set the exit code in my tagui script?

Thank you for your support and for your work, tagui is awesome!

@kensoh kensoh changed the title Exit code suggestion Exit code suggestion - to discuss adn review whether to support exit code Feb 18, 2020
@kensoh kensoh changed the title Exit code suggestion - to discuss adn review whether to support exit code Exit code suggestion - to discuss and review whether to add exit code Feb 18, 2020
@kensoh
Copy link
Member

kensoh commented Feb 18, 2020

Thanks @muratcim for sharing and @youleaf for your kind words!

The exit code from TagUI is aimed to detect whether error happens during parsing of the human language script into working JavaScript code. Thus running this.exit(1) from the script will not pass on the exit code 1.

Looping my colleague @siowyisheng into this discussion. Yi Sheng, what do you think of having the ability to have custom exit codes in TagUI script? Is this something you would like to have in v6.x / v7?

If this is to be implemented, probably a new step is needed, eg exit 1 to retain the human language syntax. And also updating the language dictionaries if that feature is retained.

Above are 2 different examples, first way is detect 'ERROR' keyword in the output log file, second way is to invoke exit code from script. Right now if an error happens during automation TagUI simply exit with this.exit() with no error code.

@lelesrc
Copy link

lelesrc commented Feb 18, 2020

If this can be useful, at the following link you'll find standard exit codes in glibc (adopted by linux, *bsd and also osx that doesn't use glibc). AFAIK, windows uses different exit codes though.

https://sourceware.org/git/?p=glibc.git;a=blob_plain;f=misc/sysexits.h;hb=0f1e40d49c1d4871fa9d7b7efdc7fca7f5ac01c0

Didn't know 1 was used for script parsing errors. This is useful and perfectly makes sense; anyway being able to catch run errors too would be great in use cases where script launch is automated.

@kensoh
Copy link
Member

kensoh commented Apr 1, 2020

Bumping my colleague @siowyisheng for inputs

@kensoh kensoh added query and removed discussion labels Apr 2, 2020
@kensoh
Copy link
Member

kensoh commented Apr 14, 2020

Hi @muratcim and @youleaf thanks for your inputs! 👍🏻

I'll have a look this week to see if there is a good way to implement exit code.

@kensoh
Copy link
Member

kensoh commented Apr 28, 2020

Hi Guys, I've looked at this. Some findings -

The current architecture does not support exiting with error level 1 even if there is an error, for example an element not found. Similarly, doing a this.exit(1); would not work (@youleaf). This is because of the following lines in tagui and tagui.cmd.

In order to both capture log files and also output the automation execution to screen, the execution is piped into the tee command. However, that means that the error level returned back would be the error level of tee command which is 0, and never 1, even if explicitly set.

macOS / Linux

"$CASPERJS_EXECUTABLE" "$1".js $params$api | tee -a "$1".log

Windows

casperjs "%flow_file%.js" %params%!api! | tee -a "%flow_file%.log"

However, @muratcim method should be doable even in v6, by hijacking log file before it is deleted by default. The following lines should do the job, by adding to just before log files are deleted.

Windows

rem give errorlevel 1 on error detected
if exist "%flow_file%.log" (
    find /c "ERROR -" "%flow_file%.log" > nul
    if not errorlevel 1 set tagui_error_code=1
)

macOS / Linux

# give errorlevel 1 on error detected
if [ -f "$1".log ]; then
if grep -q "ERROR -" "$1".log; then tagui_error_code=1; fi
fi

@kensoh
Copy link
Member

kensoh commented Apr 28, 2020

Fyi Guys, above has been implemented with above commit.

Now available with latest cutting edge version - https://github.com/kelaberetiv/TagUI/archive/master.zip

@kensoh
Copy link
Member

kensoh commented Apr 28, 2020

Hi @youleaf for your block of code, the following should work now and return errorlevel 1 -

TagUI v6

if !present('LOGOUT')
{
  echo ERROR - credentials are not valid `username`
  this.exit(1)
}

@kensoh kensoh added feature and removed query labels Apr 28, 2020
@kensoh
Copy link
Member

kensoh commented Apr 28, 2020

@muratcim and @youleaf thanks for your contributions and patience!

Closing the issue for now until further inputs or issues.

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

No branches or pull requests

3 participants