::: RC8 Update! ::: ::::::::::::::::::::::::::::::::::::::::::::::::: ::: ErrorHandling.bat by -JpE- 20220628231816 ::: ::::::::::::::::::::::::::::::::::::::::::::::::: ::: This has settled in nicely and is ::: Great to the level at which below it are hard hat, ::: YEO, Top Secret Development areas. Jp Aug 17th, 23. if not defined util3 set util3="%bats%\utility3.bat" ::: ^^^^^^^^^^^^^^^^^^^^^^^^^^^ if not defined vers set vers=v8.7.0.10 20231108073214 by -JpE- title Error: #%errorlevel% on %date% @ %time% in %vers% ::: set testwell=3 to enter full test mode. set /a testwell=0 REM set /a testwell=1 REM if %code2% equ 7 set /a testwell=3 REM if %code2% equ 7 set /a testwell=5 if %code2% equ 7 set /a testwell=1 rem ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ NOTE! set "txt21=%~1" & set "sndr42=%~2" ::: Proof of Concept for makeline function. :welcome set chars2Pad=*-=- REM call %util3% charrev :revchars "%chars2Pad%" set /a counter213=0 set txt2=Welcome to the Error Handling Module rem Degradated all the below to one line now! call %util3% t :middleman "%chars2Pad%" "%txt2%" REM call %util3% line2 :makeline "%chars2Pad%" "%txt2%" REM call %util3% pd1 pd2 "%line2%" "%chars2Pad%" "%txt2%" REM echo . & echo %line2% REM echo %charrev%%pd1% %txt2% %pd2%%charrev% REM echo %line2% & echo . ::: See utility3.bat for the functions that were here! :start if not exist %util3% echo . & echo Can't find utility3.bat! & echo . & pause & echo . & exit /b set txt=Backup if not defined r3v3rs3 set /a r3v3rs3=1 if %r3v3rs3% equ 2 set txt=RESTORE set chars2Pad=-=* call %util3% charrev :revchars "%chars2Pad%" echo . & set myLine1=Calling ErrorHandling.bat %vers% call %util3% line4 :makeline "%chars2Pad%" "%myLine1%" call %util3% sizestr1 :strlen "%line4%" set myLine2=ATTENTION: An Error Occurred in the %oper% %txt% Operation! call %util3% line0 :makeline "%chars2Pad%" "%myLine2%" call %util3% sizestr2 :strlen "%line0%" set /a lgr0=0 & set /a gap1=1 & set /a gap2=1 if %sizestr1% gtr %sizestr2% set /a lgr0=1 if %sizestr2% gtr %sizestr1% set /a lgr0=2 if %lgr0% equ 0 if %testwell% gtr 2 ( echo The lines are the same size!) if %lgr0% equ 1 if %testwell% gtr 2 echo line1 is longer. if %lgr0% equ 2 if %testwell% gtr 2 echo line2 is longer. if %testwell% gtr 2 echo . if %lgr0% equ 2 set line4=%line0% ::: Now that that's settled we can just... call %util3% gappa1 gappa2 "%line4%" "%chars2Pad%" "%myLine1%" call %util3% gappa3 gappa4 "%line4%" "%chars2Pad%" "%myLine2%" echo %line4% & echo %charrev%%gappa1% %myLine1% %gappa2%%charrev% echo %line4% & echo %charrev%%gappa3% %myLine2% %gappa4%%charrev% echo %line4% & echo . if not defined where set /a where=0 if %where% gtr 5 goto fatal if %code2% equ 5 goto nothingSent if %code2% neq 7 if exist %test% goto unhandled ::: SPLIT DOWN TO ISOLATE and Test NEWEST CODE BELOW. if %testwell% gtr 1 call :testcode if %testwell% gtr 0 goto tester if %testwell% gtr 0 echo . & echo ReTesting... & echo . & pause & echo . if %testwell% gtr 1 goto return :::=[ ACTIONS ]=::: :drive echo %l2% & echo . echo " >>===> UNLOCK BITLOCKER for D:\ AND TRY AGAIN." echo . & set msg="Are you ready to try again? (Y/n): " choice /c yn /n /t 180 /d y /m %msg% echo . & echo %l2% & if %errorlevel% neq 2 set /a exit2=5 if %errorlevel% neq 1 if %counter213% lss 10 ( set /a counter213+=1 & goto drive ) goto return :okay echo . echo %sl% echo **** Operation (s) Cancelled by: %username% **** echo %sl% echo . echo %line4% goto return ::: Fatal Error! ** if %where% gtr 5 ** :fatal echo %l2% & echo . & echo %sl% echo ** "FATAL ERROR: #"%where% <-===<< ** echo **** "copies_backups.bat" Can't be Found! **** echo %sl% & echo . & pause & echo . & echo %l2% & set /a exit2=6 goto return ::: echo if %where% equ 1 thru 4 then blah blah bla ::: originally Called from copy_control.bat :unhandled if %where% equ 1 goto drive echo . & echo %time% & echo . set msg1=An unhandled exception occurred set msg2=in the copy-subs somewhere: set msg3=The where code == %where% call %util3% line :makeline "%chars2Pad%" "%msg1%" echo %line% & echo %charrev% %msg1% %charrev% & echo %line% call %util3% s1 s2 "%line%" "%chars2Pad%" "%msg2%" echo %charrev%%s1% %msg2% %s2%%charrev% & echo %line% call %util3% s1 s2 "%line%" "%chars2Pad%" "%msg3%" echo %charrev%%s1% %msg3% %s2%%charrev% & echo %line% if %testwell% gtr 0 echo . & set msg="Test run :unh again? (y/N): " if %testwell% gtr 0 choice /c yn /n /t 300 /d n /m %msg% if %testwell% gtr 0 if %errorlevel% gtr 1 echo . & echo Bye! & echo . & echo See ya... & echo . & exit exit /b ::: By contrast, the :padder function maintains programmable left end spacing and merely fills in the end of the line to match the parms given by l1, I think it is offhand. :testcode echo . & echo errorlevel == %errorlevel% & echo . echo code2 == %code2% & echo . & pause & echo . exit /b %errorlevel% :::=-[ Fairly good to here.]-=::: :::-=[ DANGER! UNDER CONSTRUCTION. HARD HAT REQUIRED BELOW THIS LEVEL! ]=-::: :tester if %code2% neq 7 (goto drive) else ( call :next nextcall "%txt21%" "%sndr42%" ) if %errorlevel% neq 0 echo . & echo OH NO! & echo . & pause & echo . & goto return ::: It is now implicit that errorlevel is zero and code.2 == 7! if %testwell% lss 1 echo . & echo NOT IN TEST MODE RIGHT NOW! & echo . & set /a code2=0 & goto return if not defined nextcall goto duh if "%nextcall%" equ "" goto duh call :%nextcall% result6 %sndr42% ::: calls next1 or next2 if not defined result6 set result6=No results were returned. if "%result6%" equ "" set result6=No result found. set msg4=Result: %result6% set chrs=-=-/\-=-\/ REM set chrs=-=*/\ call %util3% t :middleman "%chrs%" "%msg4%" if %testwell% gtr 1 echo . & echo Test Again? & pause & CLS if %testwell% gtr 1 goto return if %testwell% gtr 0 call :unhandled exit /b :duh echo . & echo Unanticipated Exception! echo . & pause & goto unhandled ::: Route the Exception accordingly. :next setlocal & set "msg1=%~2" & set "sender=%~3" & echo . if %errorlevel% equ 0 ( echo . & echo The :next function succeeded! & echo . if %testwell% gtr 1 pause & echo . ) else ( echo . echo errorlevel == %errorlevel% was indicated. echo . ) ::: To TestWell :next2 & this else: flip line below to gtr 0 REM if %testwell% gtr 0 set sender=ErrorHandling.bat if %testwell% gtr 1 set sender=ErrorHandling.bat if "%sender%" equ "Silent_mode.bat" ( set next=next1 ) else ( set next=next2 ) if %testwell% gtr 0 echo . & echo Next is %next% & pause endlocal & set "%~1=%next%" exit /b %errorlevel% ::: See :padder error for the call. :next1 setlocal & set "sender=%~2" echo . & set line1=This error was detected from the Silent_mode.bat Code File. set chars2Pad=+=:=- call %util3% t :middleman "%chars2Pad%" "%line1%" set "result=The Padder in Util3 has FAILED." endlocal & set "%~1=%result%" exit /b %errorlevel% ::: DEVELOPING Next & as needed below. (A called function) :next2 setlocal & set "sender=%~2" set msg2=The error was detected in %sender% on %date% @ %time% set chars1=-=*=/\ ::: v8.7.0.09 20231106063214 by -JpE- call %util3% t :middleman "%chars1%" "%msg2%" ::: Saves lines, is easy to link, and reliable. ::: Change the text w/o worry of adjusting the display! ::: Reuses existing functions that are also stand-alone. ::: It makes the line reverses the chars and calculates the spacing on each side to center it in whatev chars are used! ::::::::::::::::::::::::::::::::::::::::: ::: Design to save to nFo 2log file. ::: ::::::::::::::::::::::::::::::::::::::::: set msg3=Now we have hit the next2 function! set chars2=-=_=-/\ REM set chars2=-=* call %util3% t :middleman "%chars2%" "%msg3%" set "result=I'm not sure what this will do." endlocal & set "%~1=%result%" exit /b %errorlevel% ::: Early Design Phase Only, down here. Experimenting. Flesh Out if Used. :nothingSent echo . & echo Nothing THERE-ERROR! & echo . & pause & echo . goto return REM ::: ^ UNDER CONSTRUCTION (Layout only) ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ::: Design more where handling depending on their usages. ::: ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :return REM :: TESTCODE if %testwell% gtr 2 echo . & echo The End of ErrorHandling module. & echo . & pause & echo . ::: 100% -JpE-