turnage / graw

Golang Reddit API Wrapper
MIT License
288 stars 49 forks source link

"runtime error: invalid memory address or nil pointer dereference" #55

Closed seanvm closed 4 years ago

seanvm commented 4 years ago

Using the snippet provided in the doc for a logged out user (https://godoc.org/github.com/turnage/graw/reddit) I am getting the following error: "runtime error: invalid memory address or nil pointer dereference"

Link to the go sandbox with this error: https://play.golang.org/p/_UCIn3ClpzF

Any ideas whats wrong? I'm fairly new to Go so I'm hoping it is a simple mistake.

turnage commented 4 years ago

I would check the error values.

If err != nil, the value is nil and the error value should tell you why.

You are trying to use a value which is nil.

On Fri, Nov 29, 2019 at 12:10 PM Sean van Mulligen notifications@github.com wrote:

Using the snippet provided in the doc for a logged out user ( https://godoc.org/github.com/turnage/graw/reddit) I am getting the following error: "runtime error: invalid memory address or nil pointer dereference"

Link to the go sandbox with this error: https://play.golang.org/p/_UCIn3ClpzF

Any ideas whats wrong? I'm fairly new to Go so I'm hoping it is a simple mistake.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/turnage/graw/issues/55?email_source=notifications&email_token=AAWR64BDDJTWUGGQC4IQBWLQWFSLTA5CNFSM4JTCYOV2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4H46ILVQ, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAWR64A24DVN44MXZ2GUB63QWFSLTANCNFSM4JTCYOVQ .

seanvm commented 4 years ago

@turnage thanks for responding so quickly. That was definitely my bad for not paying attention to the errors.

The error that is being returned is Get https://reddit.com/r/programming.json?raw_json=1: invalid request :path "r/programming.json?raw_json=1"

Is this path format not what I should be passing in? When making a regular http request outside of the graw package (e.g. http.NewRequest("GET", "https://reddit.com/r/programming.json?raw_json=1", nil)) it works...

turnage commented 4 years ago

That expects a permalink in the form of the “Permalink” field returned on the reddit.Post type.

I wasn’t expecting it to be used with a string passed by hand so I’m not sure of its exact syntax.

If you check and pass it in the right form, please consider making a PR updating the comments on the Thread method to explain!

On Fri, Nov 29, 2019 at 12:48 PM Sean van Mulligen notifications@github.com wrote:

@turnage https://github.com/turnage thanks for responding so quickly. That was definitely my bad for not paying attention to the errors.

The error that is being returned is Get https://reddit.com/r/programming.json?raw_json=1: invalid request :path "r/programming.json?raw_json=1"

Is this path format not what I should be passing in? When making a regular http request outside of the graw package (e.g. http.NewRequest("GET", " https://reddit.com/r/programming.json?raw_json=1", nil)) it works...

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/turnage/graw/issues/55?email_source=notifications&email_token=AAWR64AVIMQO5YELBIYFVHDQWFW2NA5CNFSM4JTCYOV2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFPPLCA#issuecomment-559871368, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAWR64HTBWCKRURPRQYWFJDQWFW2NANCNFSM4JTCYOVQ .