metalmatze / transmission-exporter

Prometheus exporter for Transmission metrics, written in Go.
MIT License
99 stars 40 forks source link

Panic on JSON deserialization when the transmission download directory doesn't exist #14

Closed utkuozdemir closed 2 years ago

utkuozdemir commented 5 years ago

I am having the following error:

2019/10/02 14:36:55 starting transmission-exporter
2019/10/02 14:36:55 no .env present
2019/10/02 14:36:59 failed to get session: json: cannot unmarshal number -1 into Go struct field Session.arguments.download-dir-free-space of type uint64
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x7ba909]

goroutine 13 [running]:
main.(*SessionCollector).Collect(0xc00012ac40, 0xc0000a86c0)
    /go/src/github.com/metalmatze/transmission-exporter/cmd/transmission-exporter/session_collector.go:134 +0xc9
github.com/prometheus/client_golang/prometheus.(*Registry).Gather.func1()
    /go/pkg/mod/github.com/prometheus/client_golang@v0.9.0-pre1.0.20181010161331-7866eead363e/prometheus/registry.go:430 +0x19d
created by github.com/prometheus/client_golang/prometheus.(*Registry).Gather
    /go/pkg/mod/github.com/prometheus/client_golang@v0.9.0-pre1.0.20181010161331-7866eead363e/prometheus/registry.go:522 +0xe12

This only happens when the download target directory for transmission doesn't exist. When I go to transmission and create the directory path for the downloads, it doesn't crash anymore.

Seems -1 is a valid value for the download-dir-free-space for transmission, and it should probably treated same as zero.

metalmatze commented 5 years ago

Guess we need to move this back to a int64 instead of a unit64. https://github.com/metalmatze/transmission-exporter/blob/e4da8ffcd62e4db2921c0671267694b2b631f3ba/session.go#L27

metalmatze commented 5 years ago

Do you want to create a PR? :)

utkuozdemir commented 5 years ago

Why not, here we go :)