diff --git a/internal/util/validator.go b/internal/util/validator.go index 3d52b7c..17fd892 100644 --- a/internal/util/validator.go +++ b/internal/util/validator.go @@ -1,12 +1,24 @@ package util -import "context" +import ( + "context" + "slices" +) func SprintErrs(errs map[string]string) string { var s string - for field, problem := range errs { - s += field + ": " + problem + "\n" + + // Sort the error keys. + errKeys := []string{} + for key := range errs { + errKeys = append(errKeys, key) + } + slices.Sort(errKeys) + + for _, key := range errKeys { + s += key + ": " + errs[key] + "\n" } + return s } diff --git a/internal/util/validator_test.go b/internal/util/validator_test.go index d688e07..75b0223 100644 --- a/internal/util/validator_test.go +++ b/internal/util/validator_test.go @@ -30,12 +30,14 @@ func TestSpringErrs(t *testing.T) { want: "foo: bar\n", }, { - name: "multiple errors", + name: "sorted errors", errs: map[string]string{ - "foo": "bar", - "baz": "qux", + "a": "foo", + "b": "bar", + "c": "baz", + "d": "qux", }, - want: "foo: bar\nbaz: qux\n", + want: "a: foo\nb: bar\nc: baz\nd: qux\n", }, }