MCPcopy Index your code
hub / github.com/labstack/echo / TestBind_formConversionErrorIncludesFieldName

Function TestBind_formConversionErrorIncludesFieldName

bind_field_error_test.go:18–32  ·  view source on GitHub ↗

Regression test for #2629: when binding form data fails a type conversion, the returned error must identify which field failed (so applications can render a useful message), instead of a bare strconv error with no field context.

(t *testing.T)

Source from the content-addressed store, hash-verified

16// returned error must identify which field failed (so applications can render a
17// useful message), instead of a bare strconv error with no field context.
18func TestBind_formConversionErrorIncludesFieldName(t *testing.T) {
19 e := New()
20 req := httptest.NewRequest(http.MethodPost, "/", strings.NewReader("number=10a"))
21 req.Header.Set(HeaderContentType, MIMEApplicationForm)
22 c := e.NewContext(req, httptest.NewRecorder())
23
24 type DTO struct {
25 Number int `form:"number"`
26 }
27 var dto DTO
28 err := c.Bind(&dto)
29
30 assert.Error(t, err)
31 assert.ErrorContains(t, err, "number", "bind error must identify the failing field")
32}

Callers

nothing calls this directly

Calls 5

BindMethod · 0.95
NewFunction · 0.85
SetMethod · 0.80
NewContextMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…