GlobalAccessSoftware

ErrorHandling.bat

Nov 16th, 2023
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 8.93 KB | Software | 0 0
  1.  
  2.  
  3. :::  RC8 Update!  :::
  4.  
  5. :::::::::::::::::::::::::::::::::::::::::::::::::
  6. ::: ErrorHandling.bat by -JpE- 20220628231816 :::
  7. :::::::::::::::::::::::::::::::::::::::::::::::::
  8.  
  9. ::: This has settled in nicely and is
  10. ::: Great to the level at which below it are hard hat,
  11. ::: YEO, Top Secret Development areas. Jp Aug 17th, 23.
  12.  
  13.   if not defined util3 set util3="%bats%\utility3.bat"
  14.  ::: ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  15.   if not defined vers set vers=v8.7.0.10 20231108073214 by -JpE-
  16.  
  17.   title Error: #%errorlevel% on %date% @ %time% in %vers%
  18.  
  19. ::: set testwell=3 to enter full test mode.
  20. set /a testwell=0
  21. REM set /a testwell=1
  22. REM if %code2% equ 7 set /a testwell=3
  23. REM if %code2% equ 7 set /a testwell=5
  24. if %code2% equ 7 set /a testwell=1
  25. rem ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ NOTE!
  26.   set "txt21=%~1" & set "sndr42=%~2"
  27.  
  28.  
  29. ::: Proof of Concept for makeline function.
  30. :welcome
  31.   set chars2Pad=*-=-
  32.  REM call %util3% charrev :revchars "%chars2Pad%"
  33.   set /a counter213=0
  34.   set txt2=Welcome to the Error Handling Module
  35.    rem Degradated all the below to one line now!
  36.     call %util3% t :middleman "%chars2Pad%" "%txt2%"
  37.  REM call %util3% line2 :makeline "%chars2Pad%" "%txt2%"
  38.  REM call %util3% pd1 pd2 "%line2%" "%chars2Pad%" "%txt2%"
  39.  REM echo . & echo %line2%
  40.  REM echo %charrev%%pd1% %txt2% %pd2%%charrev%
  41.  REM echo %line2% & echo .
  42.  
  43.   ::: See utility3.bat for the functions that were here!
  44.  
  45. :start
  46.   if not exist %util3% echo . & echo Can't find utility3.bat! & echo . & pause & echo . & exit /b
  47.   set txt=Backup
  48.   if not defined r3v3rs3 set /a r3v3rs3=1
  49.   if %r3v3rs3% equ 2 set txt=RESTORE
  50.   set chars2Pad=-=*
  51.   call %util3% charrev :revchars "%chars2Pad%"  
  52.   echo . & set myLine1=Calling ErrorHandling.bat %vers%
  53.   call %util3% line4 :makeline "%chars2Pad%" "%myLine1%"
  54.   call %util3% sizestr1 :strlen "%line4%"  
  55.   set myLine2=ATTENTION: An Error Occurred in the %oper% %txt% Operation!
  56.   call %util3% line0 :makeline "%chars2Pad%" "%myLine2%"
  57.   call %util3% sizestr2 :strlen "%line0%"
  58.  
  59.   set /a lgr0=0 & set /a gap1=1 & set /a gap2=1
  60.   if %sizestr1% gtr %sizestr2% set /a lgr0=1
  61.   if %sizestr2% gtr %sizestr1% set /a lgr0=2
  62.   if %lgr0% equ 0 if %testwell% gtr 2 (
  63.     echo The lines are the same size!)
  64.   if %lgr0% equ 1 if %testwell% gtr 2 echo line1 is longer.
  65.   if %lgr0% equ 2 if %testwell% gtr 2 echo line2 is longer.
  66.   if %testwell% gtr 2 echo .
  67.   if %lgr0% equ 2 set line4=%line0%
  68.  
  69.   ::: Now that that's settled we can just...
  70.   call %util3% gappa1 gappa2 "%line4%" "%chars2Pad%" "%myLine1%"
  71.   call %util3% gappa3 gappa4 "%line4%" "%chars2Pad%" "%myLine2%"    
  72.   echo %line4% & echo %charrev%%gappa1% %myLine1% %gappa2%%charrev%
  73.   echo %line4% & echo %charrev%%gappa3% %myLine2% %gappa4%%charrev%
  74.   echo %line4% & echo .
  75.  
  76.   if not defined where set /a where=0
  77.   if %where% gtr 5 goto fatal
  78.   if %code2% equ 5 goto nothingSent
  79.   if %code2% neq 7 if exist %test% goto unhandled
  80.  
  81.   ::: SPLIT DOWN TO ISOLATE and Test NEWEST CODE BELOW.
  82. if %testwell% gtr 1 call :testcode
  83. if %testwell% gtr 0 goto tester
  84. if %testwell% gtr 0 echo . & echo ReTesting... & echo . & pause & echo .
  85. if %testwell% gtr 1 goto return
  86.  
  87.  
  88.   :::=[ ACTIONS ]=:::
  89.  
  90. :drive
  91.   echo %l2% & echo .
  92.   echo " >>===> UNLOCK BITLOCKER for D:\ AND TRY AGAIN."
  93.   echo . & set msg="Are you ready to try again? (Y/n): "
  94.   choice /c yn /n /t 180 /d y /m %msg%
  95.   echo . & echo %l2% & if %errorlevel% neq 2 set /a exit2=5
  96.   if %errorlevel% neq 1 if %counter213% lss 10 (
  97.     set /a counter213+=1 & goto drive )
  98.   goto return
  99.  
  100.  
  101. :okay
  102.   echo .
  103.   echo %sl%
  104.   echo          ****  Operation  (s) Cancelled by: %username%  ****
  105.   echo %sl%
  106.   echo .
  107.   echo %line4%
  108.   goto return
  109.  
  110.  
  111. ::: Fatal Error! ** if %where% gtr 5 **
  112. :fatal
  113.   echo %l2% & echo . & echo %sl%
  114.   echo            **  "FATAL ERROR: #"%where% <-===<< **
  115.   echo           **** "copies_backups.bat" Can't be Found! ****
  116.   echo %sl% & echo . & pause & echo . & echo %l2% & set /a exit2=6
  117.   goto return
  118.  
  119.  
  120. :::  echo if %where% equ 1 thru 4 then blah blah bla
  121. :::  originally Called from copy_control.bat
  122. :unhandled
  123.   if %where% equ 1 goto drive
  124.   echo . & echo %time% & echo .
  125.   set msg1=An unhandled exception occurred
  126.   set msg2=in the copy-subs somewhere:
  127.   set msg3=The where code == %where%
  128.       call %util3% line :makeline "%chars2Pad%" "%msg1%"
  129.     echo %line% & echo %charrev% %msg1% %charrev% & echo %line%
  130.         call %util3% s1 s2 "%line%" "%chars2Pad%" "%msg2%"
  131.     echo %charrev%%s1% %msg2% %s2%%charrev% & echo %line%
  132.         call %util3% s1 s2 "%line%" "%chars2Pad%" "%msg3%"
  133.     echo %charrev%%s1% %msg3% %s2%%charrev% & echo %line%
  134.   if %testwell% gtr 0 echo . & set msg="Test run :unh again? (y/N): "
  135.   if %testwell% gtr 0 choice /c yn /n /t 300 /d n /m %msg%
  136.   if %testwell% gtr 0 if %errorlevel% gtr 1 echo . & echo Bye! & echo . & echo See ya... & echo . & exit
  137.   exit /b
  138.  ::: 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.
  139.  
  140.  
  141. :testcode <GLOBAL: no args sent or returned>
  142.   echo . & echo errorlevel == %errorlevel% & echo .
  143.   echo code2 == %code2% & echo . & pause & echo .
  144.   exit /b %errorlevel%
  145.  :::=-[ Fairly good to here.]-=:::
  146.  
  147.  
  148.   :::-=[ DANGER! UNDER CONSTRUCTION. HARD HAT REQUIRED BELOW THIS LEVEL! ]=-:::
  149.  
  150. :tester <string txt21, string sndr42>
  151.   if %code2% neq 7 (goto drive) else (
  152.     call :next nextcall "%txt21%" "%sndr42%" )
  153.   if %errorlevel% neq 0 echo . & echo OH NO! & echo . & pause & echo . & goto return
  154.  
  155.   ::: It is now implicit that errorlevel is zero and code.2 == 7!
  156.   if %testwell% lss 1 echo . & echo NOT IN TEST MODE RIGHT NOW! & echo . & set /a code2=0 & goto return
  157.   if not defined nextcall goto duh
  158.   if "%nextcall%" equ "" goto duh  
  159.   call :%nextcall% result6 %sndr42%
  160.  ::: calls next1 or next2
  161.   if not defined result6 set result6=No results were returned.
  162.   if "%result6%" equ "" set result6=No result found.
  163.   set msg4=Result: %result6%
  164.   set chrs=-=-/\-=-\/
  165.  REM set chrs=-=*/\
  166.       call %util3% t :middleman "%chrs%" "%msg4%"
  167.   if %testwell% gtr 1 echo . & echo Test Again? & pause & CLS
  168.   if %testwell% gtr 1 goto return
  169.   if %testwell% gtr 0 call :unhandled
  170.   exit /b
  171.  
  172.  
  173. :duh
  174.   echo . & echo Unanticipated Exception!
  175.   echo . & pause & goto unhandled
  176.  
  177.  
  178. ::: Route the Exception accordingly.
  179. :next <stringVarReturned next, stringVar msg1, stringVar sender>
  180.   setlocal & set "msg1=%~2" & set "sender=%~3" & echo .
  181.   if %errorlevel% equ 0 (
  182.     echo . & echo The :next function succeeded! & echo .
  183.     if %testwell% gtr 1 pause & echo .
  184.     ) else ( echo .
  185.       echo errorlevel == %errorlevel% was indicated.
  186.       echo . )
  187. ::: To TestWell :next2 & this else: flip line below to gtr 0
  188. REM if %testwell% gtr 0 set sender=ErrorHandling.bat
  189.  
  190. if %testwell% gtr 1 set sender=ErrorHandling.bat
  191.   if "%sender%" equ "Silent_mode.bat" (
  192.     set next=next1 ) else ( set next=next2 )
  193. if %testwell% gtr 0 echo . & echo Next is %next% & pause
  194.   endlocal & set "%~1=%next%"
  195.   exit /b %errorlevel%
  196.  
  197.  
  198. ::: See :padder error for the call.
  199. :next1 <string result, string sender>
  200.   setlocal & set "sender=%~2"
  201.   echo . & set line1=This error was detected from the Silent_mode.bat Code File.
  202.   set chars2Pad=+=:=-
  203.   call %util3% t :middleman "%chars2Pad%" "%line1%"
  204.   set "result=The Padder in Util3 has FAILED."
  205.   endlocal & set "%~1=%result%"
  206.   exit /b %errorlevel%
  207.  
  208.  
  209. ::: DEVELOPING Next & as needed below. (A called function)
  210. :next2 <string result2return, string sender>
  211.   setlocal & set "sender=%~2"
  212.   set msg2=The error was detected in %sender% on %date% @ %time%
  213.   set chars1=-=*=/\
  214.    ::: v8.7.0.09 20231106063214 by -JpE-
  215.     call %util3% t :middleman "%chars1%" "%msg2%"
  216.    ::: Saves lines, is easy to link, and reliable.
  217.    ::: Change the text w/o worry of adjusting the display!
  218.  ::: Reuses existing functions that are also stand-alone.
  219.  ::: It makes the line reverses the chars and calculates the spacing on each side to center it in whatev chars are used!
  220.  :::::::::::::::::::::::::::::::::::::::::
  221.  ::: Design to save to nFo 2log file.  :::
  222.  :::::::::::::::::::::::::::::::::::::::::
  223.  
  224.   set msg3=Now we have hit the next2 function!
  225.   set chars2=-=_=-/\
  226.  REM set chars2=-=*  
  227.     call %util3% t :middleman "%chars2%" "%msg3%"
  228.   set "result=I'm not sure what this will do."
  229.   endlocal & set "%~1=%result%"
  230.   exit /b %errorlevel%
  231.  
  232.  
  233. ::: Early Design Phase Only, down here. Experimenting. Flesh Out if Used.
  234. :nothingSent
  235.   echo . & echo Nothing THERE-ERROR! & echo . & pause & echo .
  236.  
  237.  
  238.   goto return
  239. REM ::: ^ UNDER CONSTRUCTION (Layout only)
  240.  
  241.  
  242. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  243. ::: Design more where handling depending on their usages. :::
  244. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  245.  
  246.  
  247. :return
  248. REM :: TESTCODE
  249. if %testwell% gtr 2 echo . & echo The End of ErrorHandling module. & echo . & pause & echo .
  250.  
  251.  
  252.  
  253.   ::: 100% -JpE-
  254.  
  255.  
  256.  
  257.  
Add Comment
Please, Sign In to add comment