Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: test for null in method receiver #3990

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions selfservice/flow/login/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,8 @@ func (s *ErrorHandler) PrepareReplacementForExpiredFlow(w http.ResponseWriter, r
func (s *ErrorHandler) WriteFlowError(w http.ResponseWriter, r *http.Request, f *Flow, group node.UiNodeGroup, err error) {
logger := s.d.Audit().
WithError(err).
WithRequest(r)

if f != nil {
logger = logger.WithField("login_flow", f.ToLoggerField())
}
WithRequest(r).
WithField("login_flow", f.ToLoggerField())

logger.
Info("Encountered self-service login error.")
Expand Down
5 changes: 4 additions & 1 deletion selfservice/flow/login/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,10 @@ func (f *Flow) SetReturnToVerification(to string) {
f.ReturnToVerification = to
}

func (f Flow) ToLoggerField() map[string]interface{} {
func (f *Flow) ToLoggerField() map[string]interface{} {
if f == nil {
return map[string]interface{}{}
}
return map[string]interface{}{
"id": f.ID.String(),
"return_to": f.ReturnTo,
Expand Down
7 changes: 3 additions & 4 deletions selfservice/flow/recovery/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,9 @@ func (s *ErrorHandler) WriteFlowError(
) {
logger := s.d.Audit().
WithError(recoveryErr).
WithRequest(r)
if f != nil {
logger = logger.WithField("recovery_flow", f.ToLoggerField())
}
WithRequest(r).
WithField("recovery_flow", f.ToLoggerField())

logger.
Info("Encountered self-service recovery error.")

Expand Down
19 changes: 11 additions & 8 deletions selfservice/flow/recovery/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,17 @@ func (t *Flow) GetTransientPayload() json.RawMessage {
return t.TransientPayload
}

func (t Flow) ToLoggerField() map[string]interface{} {
func (f *Flow) ToLoggerField() map[string]interface{} {
if f == nil {
return map[string]interface{}{}
}
return map[string]interface{}{
"id": t.ID.String(),
"return_to": t.ReturnTo,
"request_url": t.RequestURL,
"active": t.Active,
"type": t.Type,
"nid": t.NID,
"state": t.State,
"id": f.ID.String(),
"return_to": f.ReturnTo,
"request_url": f.RequestURL,
"active": f.Active,
"type": f.Type,
"nid": f.NID,
"state": f.State,
}
}
7 changes: 3 additions & 4 deletions selfservice/flow/registration/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,9 @@ func (s *ErrorHandler) WriteFlowError(

logger := s.d.Audit().
WithError(err).
WithRequest(r)
if f != nil {
logger = logger.WithField("registration_flow", f.ToLoggerField())
}
WithRequest(r).
WithField("registration_flow", f.ToLoggerField())

logger.
Info("Encountered self-service flow error.")

Expand Down
5 changes: 4 additions & 1 deletion selfservice/flow/registration/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,10 @@ func (f *Flow) SetReturnToVerification(to string) {
f.ReturnToVerification = to
}

func (f Flow) ToLoggerField() map[string]interface{} {
func (f *Flow) ToLoggerField() map[string]interface{} {
if f == nil {
return map[string]interface{}{}
}
return map[string]interface{}{
"id": f.ID.String(),
"return_to": f.ReturnTo,
Expand Down
7 changes: 2 additions & 5 deletions selfservice/flow/settings/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,9 @@ func (s *ErrorHandler) WriteFlowError(
) {
logger := s.d.Audit().
WithError(err).
WithRequest(r)
WithRequest(r).
WithField("settings_flow", f.ToLoggerField())

if f != nil {
logger = logger.
WithField("settings_flow", f.ToLoggerField())
}
logger.Info("Encountered self-service settings error.")

shouldRespondWithJSON := x.IsJSONRequest(r)
Expand Down
3 changes: 3 additions & 0 deletions selfservice/flow/settings/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@ func (t *Flow) GetTransientPayload() json.RawMessage {
}

func (f *Flow) ToLoggerField() map[string]interface{} {
if f == nil {
return map[string]interface{}{}
}
return map[string]interface{}{
"id": f.ID.String(),
"return_to": f.ReturnTo,
Expand Down
6 changes: 2 additions & 4 deletions selfservice/flow/verification/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,9 @@ func (s *ErrorHandler) WriteFlowError(
) {
logger := s.d.Audit().
WithError(err).
WithRequest(r)
WithRequest(r).
WithField("verification_flow", f.ToLoggerField())

if f != nil {
logger = logger.WithField("verification_flow", f.ToLoggerField())
}
logger.
Info("Encountered self-service verification error.")

Expand Down
5 changes: 4 additions & 1 deletion selfservice/flow/verification/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,10 @@ func (t *Flow) GetTransientPayload() json.RawMessage {
return t.TransientPayload
}

func (f Flow) ToLoggerField() map[string]interface{} {
func (f *Flow) ToLoggerField() map[string]interface{} {
if f == nil {
return map[string]interface{}{}
}
return map[string]interface{}{
"id": f.ID.String(),
"return_to": f.ReturnTo,
Expand Down
Loading