github.com/upcmd/up@v0.8.1-0.20230108151705-ad8b797bf04f/tests/functests/c0184.yml (about) 1 doc_meta: | 2 folder: flow-controll 3 title: finally in subtask called from block 4 head: | 5 Showcases that you can use finally block to do clean up in more complex sub task level using code block 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 22 tasks: 23 24 - 25 name: task 26 task: 27 28 - 29 func: block 30 desc: task 31 do: 32 - func: call 33 do: sub_task_layer1 34 35 - 36 name: sub_task_layer1 37 desc: sub_task_layer1 38 task: 39 40 - 41 func: call 42 loop: 43 - item1 44 - item2 45 do: 46 - sub_task_layer2 47 48 - 49 name: sub_task_layer2 50 task: 51 52 - 53 func: shell 54 name: step1 55 desc: step 1 56 do: 57 - 'echo """opening file: {{.loopitem}}"""' 58 - echo "hello"|grep "world" 59 flags: [ignoreError] 60 61 - 62 func: cmd 63 name: step2 64 desc: | 65 in this case, since there is no ignoreError, the exception was captured by task level finaly code block 66 opened file is safely closed 67 to make the flow to continue to reach step2, use ignoreError 68 do: 69 - name: print 70 cmd: step 2 71 72 desc: | 73 without rescue, the execution will return a non-zero return code in shell and also report the error 74 with rescue, the program will return 0 75 rescue: true 76 finally: 77 - 78 func: shell 79 name: close_file 80 desc: | 81 ensure the opened file is closed 82 do: 83 - echo "close the file ....."