finally/resuce support in task level

Showcases that you can can do finally cleanup and resuce the panic in the task level

Demo

source

Main task yaml file
    tasks:
    - name: task
      task:
      - func: shell
        name: step1
        desc: step 1
        do:
        - echo "opening file"
        - echo "hello"|grep "world"
      - func: cmd
        name: step2
        desc: |
          in this case, since there is no ignoreError, the exception was captured by task level finaly code block
          opened file is safely closed
          to make the flow to continue to reach step2, use ignoreError
        do:
        - name: print
          cmd: step 2
      desc: |
        without rescue, the execution will return a non-zero  return code in shell and also report the error
        with rescue, the program will return 0
      rescue: true
      finally:
      - func: shell
        name: close_file
        desc: |
          ensure the opened file is closed
        do:
        - echo "close the file ....."
    
Main log file
    loading [Config]:  ./tests/functests/upconfig.yml
    Main config:
                 Version -> 1.0.0
                  RefDir -> ./tests/functests
                 WorkDir -> cwd
              AbsWorkDir -> /up_project/up
                TaskFile -> c0175
                 Verbose -> vvv
              ModuleName -> self
               ShellType -> /bin/sh
           MaxCallLayers -> 8
                 Timeout -> 3600000
     MaxModuelCallLayers -> 256
               EntryTask -> task
      ModRepoUsernameRef -> 
      ModRepoPasswordRef -> 
    work dir: /up_project/up
    -exec task: task
    loading [Task]:  ./tests/functests/c0175
    module: [self], instance id: [dev], exec profile: []
    profile -  envVars:
    
    (*core.Cache)({
    })
    
    Task1: [task ==> task: without rescue, the execution will return a non-zero  return code in shell and also report the error
    with rescue, the program will return 0
     ]
    -Step1: [step1: step 1 ]
    self: final context exec vars:
    
    (*core.Cache)({
      "up_runtime_task_layer_number": 0
    })
    
    cmd( 1):
    echo "opening file"
    
    -
    opening file
    
    -
     .. ok
    cmd( 2):
    echo "hello"|grep "world"
    
    -
    
    -
     .. failed(suppressed if it is not the last step)
    task Finally:
    -Step1: [
    close_fileensure the opened file is closed
    ]
    self: final context exec vars:
    
    (*core.Cache)({
      "up_runtime_task_layer_number": 0
    })
    
    cmd( 1):
    echo "close the file ....."
    
    -
    close the file .....
    
    -
     .. ok
    . ok
     WARN: [Rescued in task level, but not advised!] - [setting rescue to yes/true to continue is not recommended
    it is advised to locate root cause of the problem, fix it and re-run the task again
    it is the best practice to test the execution in your ci pipeline to eliminate problems rather than dynamically fix using rescue]
    
Logs with different verbose level
Raw logs with different verbose level

What’s the difference betwee the step level and task level finally cleanup and rescue?

The only difference would be that in the step level, you would be able to obtain the exec result and then conditionally do something about it

Other references: