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

Bighugh.go fails on words without Verb Synonyms #11

Closed
OAGr opened this issue Apr 9, 2015 · 2 comments
Closed

Bighugh.go fails on words without Verb Synonyms #11

OAGr opened this issue Apr 9, 2015 · 2 comments

Comments

@OAGr
Copy link

OAGr commented Apr 9, 2015

I imagine that we need to just check if there is data in data.Verb.Syn before accessing it, but I am not sure what the cleanest way of doing that is.

bighugh.go

type words struct {
    Syn []string `json:"syn"`
}
...
syns = append(syns, data.Verb.Syn...)

curl attempt

curl http://words.bighugelabs.com/api/2/f67148bb1412bef4c1c6b25f6947e8f6/woman/json                                |
{"noun":{"syn":["adult female","charwoman","char","cleaning woman","cleaning lady","womanhood","fair sex","adult","class","cleaner","female","female person","grownup","social class","socio-economic class"],"ant":["man"],"usr":["girl"]}}%

code attempt

echo 'woman' | ./synonyms                                                                                          |
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0x463652]

goroutine 1 [running]:
thesaurus.(*BigHugh).Synonyms(0xc20808bec0, 0xc20800a440, 0x5, 0x0, 0x0, 0x0, 0x0, 0x0)
        /home/ozzie/src/thesaurus/bighugh.go:36 +0x942
main.main()
        /home/ozzie/src/github.com/oagr/blueprints/synonyms/main.go:17 +0x2a9

goroutine 8 [runnable]:
net/http.(*persistConn).readLoop(0xc20806c000)
        /usr/lib/go/src/net/http/transport.go:928 +0x9ce
created by net/http.(*Transport).dialConn
        /usr/lib/go/src/net/http/transport.go:660 +0xc9f

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
        /usr/lib/go/src/runtime/asm_amd64.s:2232 +0x1

goroutine 9 [select]:
net/http.(*persistConn).writeLoop(0xc20806c000)
        /usr/lib/go/src/net/http/transport.go:945 +0x41d
created by net/http.(*Transport).dialConn
        /usr/lib/go/src/net/http/transport.go:661 +0xcbc
@matryer
Copy link
Owner

matryer commented Apr 19, 2015

You're right, that little block should probably be a little more forgiving:

if data.Noun != nil {
    syns = append(syns, data.Noun.Syn...)
}
if data.Verb != nil {
    syns = append(syns, data.Verb.Syn...)
}

Thanks.

@matryer
Copy link
Owner

matryer commented Apr 19, 2015

Note, that calling append(syns, data.Verb.Syn...) is OK if Syn is an empty slice. It just won't do anything. The problem is that data.Verb is nil.

@matryer matryer closed this as completed Apr 19, 2015
matryer added a commit that referenced this issue Apr 19, 2015
@matryer matryer reopened this May 5, 2016
@matryer matryer closed this as completed Jul 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants