Skip to content

Commit a33a0a5

Browse files
committed
Add user friendly error
1 parent 1dac488 commit a33a0a5

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

internal/client/client.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ func (c *Client) Connect(ctx context.Context) error {
7070

7171
tlsConfig, err := c.tlsConfig()
7272
if err != nil {
73-
return err
73+
slog.Error("TLS configuration failed", "error", err)
74+
return errors.New("TLS configuration error: verify CA certificate configuration. Check server logs for details.")
7475
}
7576

7677
var conn *grpc.ClientConn

internal/client/client_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,23 @@ func TestClient_tlsConfig_NonexistentCACertPath(t *testing.T) {
313313
assert.Contains(t, err.Error(), "failed to access CA certificate")
314314
}
315315

316+
func TestClient_Connect_SanitizesTLSConfigError(t *testing.T) {
317+
client := &Client{
318+
config: &config.CentralConfig{
319+
URL: "central.stackrox.io:8443",
320+
AuthType: config.AuthTypeStatic,
321+
APIToken: "dummy",
322+
CACertPath: "/nonexistent/secret/path/ca.crt",
323+
},
324+
}
325+
326+
err := client.Connect(context.Background())
327+
require.Error(t, err)
328+
assert.NotContains(t, err.Error(), "/nonexistent/secret/path/ca.crt")
329+
assert.Contains(t, err.Error(), "TLS configuration error")
330+
assert.Contains(t, err.Error(), "Check server logs for details")
331+
}
332+
316333
// generateTestCert creates a certificate PEM with the given options, signed by the given CA.
317334
// If ca/caKey are nil, the cert is self-signed.
318335
func generateTestCert(

0 commit comments

Comments
 (0)