10000 Struct validation: invalid memory address or nil pointer dereference · Issue #276 · gookit/validate · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Struct validation: invalid memory address or nil pointer dereference #276

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

Closed
tsdevelopment opened this issue Dec 1, 2024 · 3 comments
Closed
Assignees
Labels
bug_fixed bug Something isn't working

Comments

@tsdevelopment
Copy link

System (please complete the following information):

  • OS: linux/amd64
  • GO Version: go1.23.3 linux/amd64
  • Pkg Version: v1.5.2

Describe the bug

When running struct validation the following error occurs:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0xd0 pc=0x83dfa5]

goroutine 1 [running]:
github.com/gookit/validate.(*StructData).parseRulesFromTag.func1({0x0?, 0x0?, 0xc000025a70?}, {0x0, 0x0}, {0x0, 0x0}, 0x0)
	/go/pkg/mod/github.com/gookit/validate@v1.5.2/data_source.go:300 +0xc5
github.com/gookit/validate.(*StructData).parseRulesFromTag(0xc0002140e0, 0xc0000b8420)
	/go/pkg/mod/github.com/gookit/validate@v1.5.2/data_source.go:435 +0x1c6
github.com/gookit/validate.(*StructData).Create(0xc0002140e0, {0xc000025a40, 0x1, 0xc0001d5590?})
	/go/pkg/mod/github.com/gookit/validate@v1.5.2/data_source.go:255 +0x8f
github.com/gookit/validate.mustNewValidation({0x9dfe10, 0xc0002140e0}, {0x0, 0x0})
	/go/pkg/mod/github.com/gookit/validate@v1.5.2/validate.go:283 +0xbd
github.com/gookit/validate.Struct({0x87b180?, 0xc0001f7e68?}, {0x0, 0x0, 0xd4f7a0?})
	/go/pkg/mod/github.com/gookit/validate@v1.5.2/validate.go:267 +0x3c
main.main()
	main.go:17 +0x5f
exit status 2

To Reproduce

package main

import (
	"fmt"

	"github.com/gookit/validate"
)

func main() {
	type user struct {
		Name string `validate:"required"`
		Age  int    `validate:"required_if:Name,lee"`
	}

	u := &user{Name: "lee"}
	v := validate.Struct(u)

	if v.Validate() { // validate ok
		// do something ...
	} else {
		fmt.Println(v.Errors)               // all error messages
		fmt.Println(v.Errors.One())         // returns a random error message text
		fmt.Println(v.Errors.OneError())    // returns a random error
		fmt.Println(v.Errors.Field("Name")) // returns error messages of the field
	}
}
@inhere inhere added the bug Something isn't working label Dec 1, 2024
@inhere
Copy link
Member
inhere commented Dec 1, 2024

shoud fixed in #260

@tsdevelopment
Copy link
Author

Yes, seems to be fixed in #260. Didn's see that, sorry! But there was no release since January. Are there any plans for a new release?

@inhere
Copy link
Member
inhere commented Dec 2, 2024

Yes, seems to be fixed in #260. Didn's see that, sorry! But there was no release since January. Are there any plans for a new release?

Yes, A version will be released soon

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

No branches or pull requests

2 participants
0