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

Fixed nil pointer error #10

Merged
merged 1 commit into from
Feb 24, 2024
Merged

Fixed nil pointer error #10

merged 1 commit into from
Feb 24, 2024

Conversation

Smnrgcl
Copy link
Member

@Smnrgcl Smnrgcl commented Feb 23, 2024

Hello,

The error encountered in the project is a runtime error in the form of "invalid memory address or nil pointer dereference". Upon investigating the source of this error, I noticed a nil pointer error in the github.com/octoposprime/op-be-graphql/pkg/presentation/dto/model.(*UserDto).ToModel function.

As a solution, necessary nil pointer checks were added in the (*UserDto).ToModel function, thus resolving the error. The changes were made in the relevant lines of the user.go file.

With these changes added, the function in question is now prevented from unexpectedly working with a nil object.

As seen, the solution to the error is quite simple, but I wanted to share this solution for the benefit of other developers who may encounter similar situations.

I have also included code snippets for detailed review.

// Modified Code Sections

func (u *UserDto) ToModel() *User {
    u.ModelData.UserBase = new(UserBase) // Initialize the UserBase field
    // Other code...
}

@Sddilora
Copy link
Member

Can you please add a description to the title of the pr

@Smnrgcl Smnrgcl changed the title Closes #6 Fixed nil pointer error/ closes #6 Feb 24, 2024
@husamettinarabaci husamettinarabaci added the bug Something isn't working label Feb 24, 2024
@Sddilora Sddilora merged commit 9829bb3 into phase1 Feb 24, 2024
2 checks passed
@Sddilora Sddilora deleted the fix/smnr/6/nil-pointer-error branch April 30, 2024 17:20
@Sddilora Sddilora changed the title Fixed nil pointer error/ closes #6 Fixed nil pointer error Apr 30, 2024
@Sddilora
Copy link
Member

Closes #6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants