internal/workflow: report better parameter name mismatch error

Sometimes the number of parameters matches, but their names don't.
Report that with a descriptive error rather than a nil pointer
dereference panic.

Change-Id: Ic19fa4b85d3580b9ed8575dc6e227fb146c2ecfa
Reviewed-on: https://go-review.googlesource.com/c/build/+/406414
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Dmitri Shuralyov <dmitshur@google.com>
This commit is contained in:
Dmitri Shuralyov 2022-05-13 23:48:03 -04:00
Родитель 30b481ba9b
Коммит 764449ac1b
2 изменённых файлов: 9 добавлений и 0 удалений

Просмотреть файл

@ -397,6 +397,9 @@ func (w *Workflow) validate() error {
}
paramDefs := map[string]Value{} // Key is parameter name.
for _, p := range w.def.parameters {
if _, ok := w.params[p.Name]; !ok {
return fmt.Errorf("parameter name mismatch: workflow instance doesn't have %q, but definition requires it", p.Name)
}
paramDefs[p.Name] = parameter(p)
}
for name, v := range w.params {

Просмотреть файл

@ -144,6 +144,12 @@ func TestParameters(t *testing.T) {
t.Errorf("workflow.Start didn't return an error despite a parameter count mismatch")
}
})
t.Run("NameMismatch", func(t *testing.T) {
_, err := workflow.Start(wd, map[string]interface{}{"paramA": "#1", "paramB": "#2"})
if err == nil {
t.Errorf("workflow.Start didn't return an error despite a parameter name mismatch")
}
})
t.Run("TypeMismatch", func(t *testing.T) {
_, err := workflow.Start(wd, map[string]interface{}{"param1": "#1", "param2": 42})
if err == nil {