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

GetIpInfoBatch: panic: interface conversion: interface {} is *interface {}, not *ipinfo.Core #52

Closed
jcace opened this issue Nov 14, 2022 · 10 comments · Fixed by #53
Closed
Assignees

Comments

@jcace
Copy link

jcace commented Nov 14, 2022

The GetIPInfoBatch method does not work, it always creates this error interface conversion: interface {} is *interface {}, not *ipinfo.Core

Example code:

        client := ipinfo.NewClient(nil, nil, "<TOKEN>")

	batchResult, err := client.GetIPInfoBatch(
		[]net.IP{
				net.ParseIP("1.1.1.1"),
				net.ParseIP("8.8.8.8"),
		},
		ipinfo.BatchReqOpts{
			BatchSize:       10,
			TimeoutPerBatch: 0,
			TimeoutTotal:    5,
		},
	)

	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(batchResult)

Expected output: IP Info for the batch

Actual output:

panic: interface conversion: interface {} is *interface {}, not *ipinfo.Core

goroutine 1 [running]:
github.com/ipinfo/go/v2/ipinfo.(*Client).GetIPStrInfoBatch(0x140000b6490?, {0x140000cc1c0?, 0x0?, 0x10?}, {0x0, 0x0, 0x5, 0x0, 0x0})
        /Users/jc/.gvm/pkgsets/go1.18.1/global/pkg/mod/github.com/ipinfo/go/v2@v2.8.0/ipinfo/batch.go:310 +0x17c
github.com/ipinfo/go/v2/ipinfo.(*Client).GetIPInfoBatch(0x100394ccc?, {0x140000c5e48, 0x2, 0x11?}, {0x0, 0x0, 0x5, 0x0, 0x0})
        /Users/jc/.gvm/pkgsets/go1.18.1/global/pkg/mod/github.com/ipinfo/go/v2@v2.8.0/ipinfo/batch.go:282 +0x8c
main.GenerateIpinfoMap({0x10046b5a0?, 0x140000c5f50?, 0x140000c5f28?})
        /Users/jc/Dev/ipinfo_api.go:22 +0x250
main.main()
        /Users/jc/Dev/main.go:55 +0xd4
exit status 2
@UmanShahzad
Copy link
Contributor

Are you putting a real token and not getting rate limited? Either of these may cause the issue, but please do confirm.

@rm-Umar
Copy link
Contributor

rm-Umar commented Nov 15, 2022

I just checked and I was able to replicate the error if you put an empty string in the client as token then it throws this error

client := ipinfo.NewClient(nil, nil, "")

So putting the token should solve your issue.
cc: @UmanShahzad

@UmanShahzad
Copy link
Contributor

I see. Can we fix so that it doesn't panic, and instead just returns an error?

@jcace
Copy link
Author

jcace commented Nov 15, 2022

I am using my real token - just redacted it for the post:

	client := ipinfo.NewClient(nil, nil, "39b807185xxxxx")

Doesn't seem like I'm being rate limited - brand new account and testing with only a single IP in the request

Screenshot 2022-11-15 at 12 57 31 PM

@rm-Umar
Copy link
Contributor

rm-Umar commented Nov 16, 2022

I see. Can we fix so that it doesn't panic, and instead just returns an error?

I think a simple check on the token can solve this issue.

@rm-Umar
Copy link
Contributor

rm-Umar commented Nov 16, 2022

I am using my real token - just redacted it for the post:

	client := ipinfo.NewClient(nil, nil, "39b807185xxxxx")

Doesn't seem like I'm being rate limited - brand new account and testing with only a single IP in the request

Screenshot 2022-11-15 at 12 57 31 PM

I am unable to replicate this error I've tried different scenarios and the only scenario giving me this error is when you pass "" as token. I also noticed you are using SDK version 2.8.0 you can try updating to 2.9.0 meanwhile I'll look into it further and try to find the cause of this problem.

@rm-Umar
Copy link
Contributor

rm-Umar commented Nov 16, 2022

The error also occurs if we put an invalid IP in the batch request

batchResult, err := client.GetIPInfoBatch(
		[]net.IP{
			net.ParseIP("1.1.1.1"),
			net.ParseIP("8.8.8.8"),
			net.ParseIP(""),
			}

@UmanShahzad
Copy link
Contributor

Will do a patch release then you can try again.

@rm-Umar
Copy link
Contributor

rm-Umar commented Nov 16, 2022

@jcace just released v2.9.1 your error should be fixed in this patch.
Thank you for your feedback! 😃

@jcace
Copy link
Author

jcace commented Nov 17, 2022

thanks! looks like it works now. Tested v2.9.1

Must've been an invalid IP address because I'm getting expected result now. Error message is much better too when I pass in an invalid one.

@rm-Umar rm-Umar closed this as completed Nov 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants