mikf / gallery-dl

Command-line program to download image galleries and collections from several image hosting sites
GNU General Public License v2.0
11.78k stars 966 forks source link

where do i find the exit codes? #2208

Closed Butterfly-Dragon closed 2 years ago

Butterfly-Dragon commented 2 years ago

in my batch files i tend to put a "translation" of the exit codes.

Example: this is the translation of the exit codes for ROBOCOPY

:ERRORCHECK
IF %ERRORLEVEL% EQU 16 ECHO ***FATAL ERROR*** & GOTO :EOF
IF %ERRORLEVEL% EQU 15 ECHO OKCOPY + FAIL + MISMATCHES + XTRA & GOTO :EOF
IF %ERRORLEVEL% EQU 14 ECHO FAIL + MISMATCHES + XTRA & GOTO :EOF
IF %ERRORLEVEL% EQU 13 ECHO OKCOPY + FAIL + MISMATCHES & GOTO :EOF
IF %ERRORLEVEL% EQU 12 ECHO FAIL + MISMATCHES& GOTO :EOF
IF %ERRORLEVEL% EQU 11 ECHO OKCOPY + FAIL + XTRA & GOTO :EOF
IF %ERRORLEVEL% EQU 10 ECHO FAIL + XTRA & GOTO :EOF
IF %ERRORLEVEL% EQU 9 ECHO OKCOPY + FAIL & GOTO :EOF
IF %ERRORLEVEL% EQU 8 ECHO FAIL & GOTO :EOF
IF %ERRORLEVEL% EQU 7 ECHO OKCOPY + MISMATCHES + XTRA & GOTO :EOF
IF %ERRORLEVEL% EQU 6 ECHO MISMATCHES + XTRA & GOTO :EOF
IF %ERRORLEVEL% EQU 5 ECHO OKCOPY + MISMATCHES & GOTO :EOF
IF %ERRORLEVEL% EQU 4 ECHO MISMATCHES & GOTO :EOF
IF %ERRORLEVEL% EQU 3 ECHO OKCOPY + XTRA & GOTO :EOF
IF %ERRORLEVEL% EQU 2 ECHO XTRA & GOTO :EOF
IF %ERRORLEVEL% EQU 1 ECHO OKCOPY & GOTO :EOF
IF %ERRORLEVEL% EQU 0 ECHO No Change & GOTO :EOF
GOTO :EOF

i'm probably reading it wrong but i don't find a list of exit codes for gallery_dl.

Is it because they are mostly for your personal use and therefore you never bothered?

Or is it because i totally flew over where they are listed?

Hrxn commented 2 years ago

It's using sys.exit(), so gallery-dl has exit codes that get returned to stderr, e.g.

https://github.com/mikf/gallery-dl/blob/a7e4917ee1b01baa707f010056a6c0d0b8cfc334/gallery_dl/config.py#L72

But not for every possible use case, I think, and they are not really documented yet. Still usable, tho

D:\Temp>%ERRORLEVEL%
'0' is not recognized as an internal or external command,
operable program or batch file.

D:\Temp>gallery-dl
usage: gallery-dl [OPTION]... URL...
gallery-dl: error: The following arguments are required: URL
Use 'gallery-dl --help' to get a list of all options.

D:\Temp>IF %ERRORLEVEL% EQU 2 ECHO "BINGO"
"BINGO"

D:\Temp>

In Powershell you can use the built-ins $LASTEXITCODE and $?, e.g.

PS D:\Temp> gallery-dl --version
1.20.2-dev
PS D:\Temp> $?
True
PS D:\Temp> gallery-dl
usage: gallery-dl [OPTION]... URL...
gallery-dl: error: The following arguments are required: URL
Use 'gallery-dl --help' to get a list of all options.
PS D:\Temp> $?
False
PS D:\Temp>

I'm usually using exit code handling for my own scripts, but I'm actually not with gallery-dl, because it already has a good logging functionality which handles that use case for me, basically.

Butterfly-Dragon commented 2 years ago

Uh... no i meant that i wanted to know if i get an errorlevel of 73 (example)... what does that mean? because thrawling through 4 megabytes of log each time is kinda boring.

Hrxn commented 2 years ago

I think there are only a couple of exit codes.. and they don't tell you anything you couldn't gather from the logs. Why are your logs so huge? Are you logging every debug message that does not even indicate any issue?

Butterfly-Dragon commented 2 years ago

no, i have several in a batch jobs that go on forever. aside from 3 or 4 that exit after 3 entries... the rest have something like 1000 entries at the shortest, and so i reduced the abort to 3 and try and keep it that way, i am trying to find ways to cut time.

mikf commented 2 years ago

Exit codes are, like many other things, nowhere "officially" documented, but you can find a list in issue #1120.

Butterfly-Dragon commented 2 years ago

thank you very much.