-
Notifications
You must be signed in to change notification settings - Fork 4
/
c0174.yml
74 lines (64 loc) · 2.28 KB
/
c0174.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
doc_meta: |
folder: flow-controll
title: conditionally error handling
head: |
Showcases that you can use internal var up_runtime_shell_exec_result to conditionally do your own customised cleanup or business
sections:
- title: Demo
log: yes
- title: What if I want to handle a specific error
content: |
Note that in the finally steps, it uses up_runtime_shell_exec_result to obtain the shell exec exit code, error message and regular output.
In case you need to deal with a specific error, eg, by exit code, or error message, you can use if condition to implement that
related:
refs:
- title: shell func
link: ../../quick-start/c0002/
- title: error handling
link: ../../test-debug/error_handling/
- title: finally and rescue
link: ../../flow-controll/c0172/
notes:
- all finally block/task to access the failed exec contextual info and conditionally handle the error
tasks:
-
name: task
task:
-
func: shell
do:
- echo "opening file"
- echo "hello"|grep "world"
flags:
- ignoreError
finally:
-
func: shell
desc: |
ensure the opened file is closed
do:
- echo "close the file ....."
- |
echo """
exec command: {{.up_runtime_shell_exec_result.Cmd}}
error code: {{.up_runtime_shell_exec_result.Code}}
error message: {{.up_runtime_shell_exec_result.ErrMsg}}
error output: {{.up_runtime_shell_exec_result.Output}}
"""
-
func: cmd
desc: |
see if the exec context result: up_runtime_shell_exec_result is still availabe
conditional do something about the error etc
do:
- name: print
cmd: |
error message: {{.up_runtime_shell_exec_result.ErrMsg}}
if: '{{ne .up_runtime_shell_exec_result.Code 0}}'
-
func: shell
desc: |
this step will not be reached if the ignoreError flag is not set
try it yourself to remove the ignoreError flag and see difference
do:
- echo "extra step ..."