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