github.com/upcmd/up@v0.8.1-0.20230108151705-ad8b797bf04f/tests/functests/c0175.yml (about)

     1  doc_meta: |
     2    folder: flow-controll
     3    title: finally/resuce support in task level
     4    head: |
     5      Showcases that you can can do finally cleanup and resuce the panic in the task level
     6  
     7    sections:
     8      - title: Demo
     9        log: yes
    10  
    11      - title: What's the difference betwee the step level and task level finally cleanup and rescue?
    12        content: |
    13          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
    14  
    15    related:
    16      refs:
    17        - title: shell func
    18          link: ../../quick-start/c0002/
    19        - title: error handling
    20          link: ../../test-debug/error_handling/
    21        - title: finally and rescue
    22          link: ../../flow-controll/c0174/
    23  
    24  notes:
    25    - add finally support to tasks level
    26  
    27  tasks:
    28  
    29    -
    30      name: task
    31      task:
    32  
    33        -
    34          func: shell
    35          name: step1
    36          desc: step 1
    37          do:
    38            - echo "opening file"
    39            - echo "hello"|grep "world"
    40  
    41        -
    42          func: cmd
    43          name: step2
    44          desc: |
    45            in this case, since there is no ignoreError, the exception was captured by task level finaly code block
    46            opened file is safely closed
    47            to make the flow to continue to reach step2, use ignoreError
    48          do:
    49            - name: print
    50              cmd: step 2
    51  
    52      desc: |
    53        without rescue, the execution will return a non-zero  return code in shell and also report the error
    54        with rescue, the program will return 0
    55      rescue: true
    56      finally:
    57        -
    58          func: shell
    59          name: close_file
    60          desc: |
    61            ensure the opened file is closed
    62          do:
    63            - echo "close the file ....."