You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm currently writing a CRUD microservice that uses zap logger. When I create an object via my POST endpoint, I have no problems. Here's my object model:
As you can see from the tags, QualifiedName is required and unique. So if I try to recreate the same object, I should get an error indicating that an object with that same qualified name already exists.
Here's the code that handles creating the object:
func handleCreateField(c *gin.Context, svc field.RegistrationService) {
user := auth.GetUser(c)
var f field.Field
var err error
//FIXME: Currently trying to create an object that already exists leads to 'bad access: nil dereference'somewhere inside of a ShouldBondJSON goroutine
if err = c.ShouldBindJSON(&f); err != nil {
_ = c.Error(err)
return
}
if user != nil {
f.PartnerId = user.PartnerID
f.CreatedBy = user.ID
f.UpdatedBy = f.CreatedBy
}
if err = svc.Create(&f); err != nil {
_ = c.Error(err)
return
}
c.JSON(http.StatusOK, f)
}
If I step through the debugger, the error occurs somewhere in the call to c.ShouldBindJSON(&f). Eventually, stepping though leads to the "bad access: nil dereference" message triggered in this part of sugar.go.
func (s *SugaredLogger) log(lvl zapcore.Level, template string, fmtArgs []interface{}, context []interface{}) {
// If logging at this level is completely disabled, skip the overhead of
// string formatting.
if lvl < DPanicLevel && !s.base.Core().Enabled(lvl) {
return
}
At this point, the request never returns a response, and continuing from the breakpoint I placed on if lvl < DPanicLevel && !s.base.Core().Enabled(lvl) just returns to this breakpoint, so it appears to be stuck in a goroutine or loop that won't terminate on its own. I would note that that value of s here is nil which is probably why I'm encountering this. What I can't figure out is why s is nil.
Any help or suggestions appreciated. Note that I'm also cross-posting on StackOverflow.
The text was updated successfully, but these errors were encountered:
Hi @Osiris1975, your issue has a combination of gin, gorm, and zap, and it's hard to tease apart what exactly is the issue. The code samples you provided have no reference to a logger or a log call, and so it's not clear how the log call even happens.
It's possible that your configuration to create the logger is incorrect (#777) or your logger is not created at all, so check those first.
If you continue to see this issue, please provide a minimal reproduction without any other libraries, so we can investigate the issue further.
Hi,
I'm currently writing a CRUD microservice that uses zap logger. When I create an object via my POST endpoint, I have no problems. Here's my object model:
As you can see from the tags, QualifiedName is required and unique. So if I try to recreate the same object, I should get an error indicating that an object with that same qualified name already exists.
Here's the code that handles creating the object:
If I step through the debugger, the error occurs somewhere in the call to
c.ShouldBindJSON(&f)
. Eventually, stepping though leads to the "bad access: nil dereference" message triggered in this part ofsugar.go
.At this point, the request never returns a response, and continuing from the breakpoint I placed on
if lvl < DPanicLevel && !s.base.Core().Enabled(lvl)
just returns to this breakpoint, so it appears to be stuck in a goroutine or loop that won't terminate on its own. I would note that that value ofs
here isnil
which is probably why I'm encountering this. What I can't figure out is whys
is nil.Any help or suggestions appreciated. Note that I'm also cross-posting on StackOverflow.
The text was updated successfully, but these errors were encountered: