Add log for Binding Object Data Error #11918

Open
opened 2025-11-02 09:51:49 -06:00 by GiteaMirror · 0 comments
Owner

Originally created by @BaiZe1998 on GitHub (Oct 27, 2023).

Feature Description

branch: main

desc: I think maybe we could add a log for binding an obj to a handler's context data error at
https://github.com/go-gitea/gitea/blob/main/modules/web/route.go#L21C12-L21C12
Because the lack of error log really bothers me when submitting parameters through the browser.

just like:

// Bind binding an obj to a handler's context data
func Bind[T any](_ T) http.HandlerFunc {
	return func(resp http.ResponseWriter, req *http.Request) {
		theObj := new(T) // create a new form obj for every request but not use obj directly
		data := middleware.GetContextData(req.Context())
		errors := binding.Bind(req, theObj)
		if errors.Len() > 0 {
			log.Error("Bind: Binding an obj to a handler's context data error:%v, obj: %s %v\n", errors, reflect.TypeOf(theObj), theObj)
			return
		}
		SetForm(data, theObj)
		middleware.AssignForm(theObj, data)
	}
}

I've seen that api-related interfaces have added this part of the error log at bind time.
https://github.com/go-gitea/gitea/blob/main/routers/api/v1/api.go#L697C18-L697C18

image

I can help if needed.

Screenshots

No response

Originally created by @BaiZe1998 on GitHub (Oct 27, 2023). ### Feature Description branch: main desc: I think maybe we could add a log for binding an obj to a handler's context data error at https://github.com/go-gitea/gitea/blob/main/modules/web/route.go#L21C12-L21C12 Because the lack of error log really bothers me when submitting parameters through the browser. just like: ``` golang // Bind binding an obj to a handler's context data func Bind[T any](_ T) http.HandlerFunc { return func(resp http.ResponseWriter, req *http.Request) { theObj := new(T) // create a new form obj for every request but not use obj directly data := middleware.GetContextData(req.Context()) errors := binding.Bind(req, theObj) if errors.Len() > 0 { log.Error("Bind: Binding an obj to a handler's context data error:%v, obj: %s %v\n", errors, reflect.TypeOf(theObj), theObj) return } SetForm(data, theObj) middleware.AssignForm(theObj, data) } } ``` I've seen that api-related interfaces have added this part of the error log at bind time. https://github.com/go-gitea/gitea/blob/main/routers/api/v1/api.go#L697C18-L697C18 <img width="959" alt="image" src="https://github.com/go-gitea/gitea/assets/45022150/5811babb-7899-4336-8677-789646aa12d7"> I can help if needed. ### Screenshots _No response_
GiteaMirror added the type/proposal label 2025-11-02 09:51:49 -06:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#11918