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

     1  doc_meta: |
     2    folder: flow-controll
     3    title: finally subtask no ignoreError
     4    head: |
     5      Showcases that you can can do finally cleanup and resuce the panic in the sub task level
     6  
     7    sections:
     8      - title: Demo
     9        log: yes
    10  
    11    related:
    12      refs:
    13        - title: shell func
    14          link: ../../quick-start/c0002/
    15        - title: error handling
    16          link: ../../test-debug/error_handling/
    17        - title: finally and rescue
    18          link: ../../flow-controll/c0174/
    19        - title: finally and rescue
    20          link: ../../flow-controll/c0183/
    21        - title: finally and rescue
    22          link: ../../flow-controll/c0184/
    23  
    24  notes:
    25    - add finally support to tasks level
    26  
    27  tasks:
    28  
    29    -
    30      name: task
    31      task:
    32  
    33        -
    34          func: call
    35          desc: task
    36          do:
    37            - sub_task_layer1
    38  
    39    -
    40      name: sub_task_layer1
    41      desc: sub_task_layer1
    42      task:
    43  
    44        -
    45          func: call
    46          loop:
    47            - item1
    48            - item2
    49          do:
    50            - sub_task_layer2
    51  
    52    -
    53      name: sub_task_layer2
    54      task:
    55  
    56        -
    57          func: shell
    58          name: step1
    59          desc: step 1
    60          do:
    61            - 'echo """opening file: {{.loopitem}}"""'
    62            - echo "hello"|grep "world"
    63  
    64        -
    65          func: cmd
    66          name: step2
    67          desc: |
    68            in this case, since there is no ignoreError, the exception was captured by task level finaly code block
    69            opened file is safely closed
    70            to make the flow to continue to reach step2, use ignoreError
    71          do:
    72            - name: print
    73              cmd: step 2
    74  
    75      desc: |
    76        without rescue, the execution will return a non-zero  return code in shell and also report the error
    77        with rescue, the program will return 0
    78      rescue: true
    79      finally:
    80        -
    81          func: shell
    82          name: close_file
    83          desc: |
    84            ensure the opened file is closed
    85          do:
    86            - echo "close the file ....."