bitsbeats / drone-tree-config

Drone helper for mono repositories.
Apache License 2.0
103 stars 24 forks source link

Failed SCM connections should be handled properly #10

Closed aku closed 4 years ago

aku commented 4 years ago

plugin.NewScmClient should return an error if something goes wrong. Currently, it returns nil client that causes panic later on.

Here is a log:

time="2019-12-12T08:25:46Z" level=info msg="c1343e95-2072-41f4-a477-5f6f035ca14e _EDITED_"

time="2019-12-12T08:25:46Z" level=error msg="**Unable to connect to SCM server**."

time="2019-12-12T08:25:46Z" level=info msg="c1343e95-2072-41f4-a477-5f6f035ca14e match: _EDITED_"

time="2019-12-12T08:25:46Z" level=info msg="c1343e95-2072-41f4-a477-5f6f035ca14e finished"

2019/12/12 08:25:46 **http: panic serving 192.168.80.12:40516: runtime error: invalid memory address or nil pointer dereference**

goroutine 6 [running]:

net/http.(*conn).serve.func1(0xc000075400)

    /usr/local/go/src/net/http/server.go:1767 +0x139

panic(0x96fbc0, 0xe251f0)

    /usr/local/go/src/runtime/panic.go:679 +0x1b2

github.com/bitsbeats/drone-tree-config/plugin.(*Plugin).getScmChanges(0xc0000c8230, 0xadf2c0, 0xc0000fa400, 0xc00010d920, 0xc00011a7b0, 0x26, 0x1, 0xc0000f7b30, 0xb)

    /go/src/github.com/bitsbeats/drone-tree-config/plugin/scm.go:58 +0x313

github.com/bitsbeats/drone-tree-config/plugin.(*Plugin).Find(0xc0000c8230, 0xadf2c0, 0xc0000fa400, 0xc000118840, 0x0, 0x0, 0x0)

    /go/src/github.com/bitsbeats/drone-tree-config/plugin/plugin.go:75 +0x424

github.com/drone/drone-go/plugin/config.(*handler).ServeHTTP(0xc00005f350, 0xade4c0, 0xc0001240e0, 0xc0000ca300)

    /go/pkg/mod/github.com/drone/drone-go@v1.0.4/plugin/config/handler.go:84 +0x21b

net/http.(*ServeMux).ServeHTTP(0xe32be0, 0xade4c0, 0xc0001240e0, 0xc0000ca300)

    /usr/local/go/src/net/http/server.go:2387 +0x1bd

net/http.serverHandler.ServeHTTP(0xc0000d6000, 0xade4c0, 0xc0001240e0, 0xc0000ca300)

    /usr/local/go/src/net/http/server.go:2802 +0xa4

net/http.(*conn).serve(0xc000075400, 0xadf2c0, 0xc00005a500)

    /usr/local/go/src/net/http/server.go:1890 +0x875

created by net/http.(*Server).Serve

    /usr/local/go/src/net/http/server.go:2927 +0x38e
foosinn commented 4 years ago

Can you please try with this docker image? bitsbeats/drone-tree-config:issue10

Sadly we are not using bitbucket.

aku commented 4 years ago

It's not related to the BitBucket but a general error in the source code. If the plugin can not connect to a SCM provider it should not continue. I will try to get to this issue somewhere next week. You can try it with GitHub by providing some incorrect connection/auth data, it should fail with the same runtime exception

aku commented 4 years ago

I've noticed you have pushed a new commit. I will try to get back to this issue, thanks for a quick fix

foosinn commented 4 years ago

this should be fixed by 421951ac1aa6735da8f586a0ca56957ce3a07a2b

I think its enough to leave one ticket open.