@@ -25,7 +25,7 @@ func ReadWorkflow(name string, rawWorkflow []byte) (*Workflow, error) {
25
25
parsed := make (map [string ]interface {})
26
26
err := yaml .Unmarshal (rawWorkflow , & parsed )
27
27
if err != nil {
28
- return nil , errors .Wrap (err , "Unable to parse workflow." )
28
+ return nil , errors .Wrap (err , "Unable to parse workflow as YAML ." )
29
29
}
30
30
if on , ok := parsed ["on" ]; ok {
31
31
switch typedOn := on .(type ) {
@@ -41,28 +41,38 @@ func ReadWorkflow(name string, rawWorkflow []byte) (*Workflow, error) {
41
41
for event , eventConfiguration := range typedOn {
42
42
if event == workflowDispatch {
43
43
workflow .Dispatchable = true
44
- // TODO: How many of the switches can be converted to type assertions and do we need to handle errors?
45
- switch typedEventConfiguration := eventConfiguration .(type ) {
46
- case map [interface {}]interface {}:
44
+ if eventConfiguration != nil {
45
+ typedEventConfiguration , ok := eventConfiguration .(map [interface {}]interface {})
46
+ if ! ok {
47
+ return nil , errors .Errorf ("Workflow dispatch configuration had unexpected type %T." , eventConfiguration )
48
+ }
47
49
if inputs , ok := typedEventConfiguration ["inputs" ]; ok {
48
- switch typedInputs := inputs .(type ) {
49
- case map [interface {}]interface {}:
50
- for inputName , inputConfiguration := range typedInputs {
51
- input := Input {
52
- Name : inputName .(string ),
53
- }
54
- if inputDescription , ok := inputConfiguration .(map [interface {}]interface {})["description" ]; ok {
55
- input .Description = inputDescription .(string )
50
+ typedInputs , ok := inputs .(map [interface {}]interface {})
51
+ if ! ok {
52
+ return nil , errors .Errorf ("Workflow dispatch configuration inputs had unexpected type %T." , inputs )
53
+ }
54
+ for inputName , inputConfiguration := range typedInputs {
55
+ typedInputConfiguration , ok := inputConfiguration .(map [interface {}]interface {})
56
+ if ! ok {
57
+ return nil , errors .Errorf ("Input configuration for %s had unexpected type %T." , inputName , inputConfiguration )
58
+ }
59
+ input := Input {
60
+ Name : inputName .(string ),
61
+ }
62
+ if inputDescription , ok := typedInputConfiguration ["description" ]; ok {
63
+ input .Description , ok = inputDescription .(string )
64
+ if ! ok {
65
+ return nil , errors .Errorf ("Input description for %s had unexpected type %T." , inputName , inputDescription )
56
66
}
57
- workflow .Inputs = append (workflow .Inputs , input )
58
67
}
68
+ workflow .Inputs = append (workflow .Inputs , input )
59
69
}
60
70
}
61
71
}
62
72
}
63
73
}
64
74
default :
65
- return nil , errors .Errorf ("Unable to parse workflow \" on\" clause. Unexpected type %T." , on ) // TODO: Should we error here?
75
+ return nil , errors .Errorf ("Unable to parse workflow \" on\" clause. Unexpected type %T." , on )
66
76
}
67
77
}
68
78
return & workflow , nil
0 commit comments