mirror of
https://github.com/k8sgpt-ai/k8sgpt.git
synced 2026-07-17 10:20:41 +00:00
grpc.NewClient returns a nil *ClientConn when it fails (for example on an invalid connection string). Store and Load registered defer conn.Close() before checking the returned error, so a client-creation failure triggered a nil pointer dereference in the deferred Close instead of returning the error. Move defer conn.Close() to after the error check in both methods. Add a regression test that drives Store and Load with an invalid connection string and asserts they return an error without panicking. The deferred conn.Close() now discards its error with a plain _ = conn.Close() rather than logging it: grpc's ClientConn.Close() only returns a non-nil error on a double-close, which can't happen from a single call site here, so a logging branch would be dead code that patch coverage can never satisfy. Signed-off-by: Anas Khan <83116240+anxkhn@users.noreply.github.com>