deleting a non-existent admin results in a panic. The panic doesn't crash, i.e. backend recovers and tool is still usable.
Should add error handling instead of panic.
mkasun@firefly:~/sandbox/netmaker$ go run . &
[1] 16186
mkasun@firefly:~/sandbox/netmaker$ 2021/03/28 17:45:05 Server starting...
2021/03/28 17:45:05 Database connecting...
2021/03/28 17:45:05 Database Connected.
REST Server succesfully started on port 8081 (REST)
Agent Server succesfully started on port :50051 (gRPC)
deleteWrongAdmin.sh
2021/03/28 17:45:13 server.go:3139: http: panic serving 127.0.0.1:53442: runtime error: invalid memory address or nil pointer dereference
goroutine 23 [running]:
net/http.(*conn).serve.func1(0xc0003ed5e0)
/snap/go/7221/src/net/http/server.go:1824 +0x153
panic(0xcd3300, 0x13f7500)
/snap/go/7221/src/runtime/panic.go:971 +0x499
github.com/gravitl/netmaker/controllers.deleteUser(0xfc3630, 0xc00039a1c0, 0xc0002dee00)
/home/mkasun/sandbox/netmaker/controllers/userHttpController.go:448 +0x189
net/http.HandlerFunc.ServeHTTP(0xde7928, 0xfc3630, 0xc00039a1c0, 0xc0002dee00)
/snap/go/7221/src/net/http/server.go:2069 +0x44
github.com/gravitl/netmaker/controllers.authorizeUser.func1(0xfc3630, 0xc00039a1c0, 0xc0002dee00)
/home/mkasun/sandbox/netmaker/controllers/userHttpController.go:175 +0x1f0
net/http.HandlerFunc.ServeHTTP(0xc00000eff0, 0xfc3630, 0xc00039a1c0, 0xc0002dee00)
/snap/go/7221/src/net/http/server.go:2069 +0x44
github.com/gorilla/mux.(*Router).ServeHTTP(0xc0001029c0, 0xfc3630, 0xc00039a1c0, 0xc0002dec00)
/home/mkasun/go/pkg/mod/github.com/gorilla/mux@v1.8.0/mux.go:210 +0xd3
github.com/gorilla/handlers.(*cors).ServeHTTP(0xc0003bcea0, 0xfc3630, 0xc00039a1c0, 0xc0002dec00)
/home/mkasun/go/pkg/mod/github.com/gorilla/handlers@v1.5.1/cors.go:54 +0x103e
net/http.serverHandler.ServeHTTP(0xc00039a0e0, 0xfc3630, 0xc00039a1c0, 0xc0002dec00)
/snap/go/7221/src/net/http/server.go:2887 +0xa3
net/http.(*conn).serve(0xc0003ed5e0, 0xfc4300, 0xc0003da340)
/snap/go/7221/src/net/http/server.go:1952 +0x8cd
created by net/http.(*Server).Serve
/snap/go/7221/src/net/http/server.go:3013 +0x39b
curl: (52) Empty reply from server
deleting a non-existent admin results in a panic. The panic doesn't crash, i.e. backend recovers and tool is still usable.
Should add error handling instead of panic.