From 6dd76587552ee7923a41e4fdca7e62fe1fa6101c Mon Sep 17 00:00:00 2001 From: luhaoling <2198702716@qq.com> Date: Tue, 19 Dec 2023 17:49:16 +0800 Subject: [PATCH] fix: update the error format --- tools/component/component.go | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/tools/component/component.go b/tools/component/component.go index 97d6b4642..28ea7a2fe 100644 --- a/tools/component/component.go +++ b/tools/component/component.go @@ -149,12 +149,12 @@ func checkMongo() (string, error) { client, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(uri)) str := "ths addr is:" + strings.Join(config.Config.Mongo.Address, ",") if err != nil { - return "", errs.Wrap(err, str) + return "", errs.Wrap(errStr(err, str)) } defer client.Disconnect(context.TODO()) if err = client.Ping(context.TODO(), nil); err != nil { - return "", errs.Wrap(err, str) + return "", errs.Wrap(errStr(err, str)) } return str, nil @@ -198,7 +198,8 @@ func checkMinio() (string, error) { // Parse endpoint URL to determine if SSL is enabled u, err := url.Parse(endpoint) if err != nil { - return "", errs.Wrap(err) + str := "the endpoint is:" + endpoint + return "", errs.Wrap(errStr(err, str)) } secure := u.Scheme == "https" || useSSL == "true" @@ -207,20 +208,22 @@ func checkMinio() (string, error) { Creds: credentials.NewStaticV4(accessKeyID, secretAccessKey, ""), Secure: secure, }) - str := "the addr is:" + u.Host + str := "ths addr is:" + u.Host if err != nil { - return "", errs.Wrap(err, str) + strs := fmt.Sprintf("%v;host:%s,accessKeyID:%s,secretAccessKey:%s,Secure:%v", err, u.Host, accessKeyID, secretAccessKey, secure) + return "", errs.Wrap(err, strs) } // Perform health check cancel, err := minioClient.HealthCheck(time.Duration(minioHealthCheckDuration) * time.Second) if err != nil { - return "", errs.Wrap(err, str) + return "", errs.Wrap(errStr(err, str)) } defer cancel() if minioClient.IsOffline() { - return "", ErrComponentStart.Wrap("Minio server is offline", str) + str := fmt.Sprintf("Minio server is offline;%s", str) + return "", ErrComponentStart.Wrap(str) } // Check for localhost in API URL and Minio SignEndpoint @@ -263,7 +266,7 @@ func checkRedis() (string, error) { _, err := redisClient.Ping(context.Background()).Result() str := "the addr is:" + strings.Join(redisAddresses, ",") if err != nil { - return "", errs.Wrap(err, str) + return "", errs.Wrap(errStr(err, str)) } return str, nil @@ -284,14 +287,14 @@ func checkZookeeper() (string, error) { str := "the addr is:" + address c, _, err := zk.Connect(zookeeperAddresses, time.Second) // Adjust the timeout as necessary if err != nil { - return "", errs.Wrap(err, str) + return "", errs.Wrap(errStr(err, str)) } defer c.Close() // Set authentication if username and password are provided if username != "" && password != "" { if err := c.AddAuth(schema, []byte(username+":"+password)); err != nil { - return "", errs.Wrap(err) + return "", errs.Wrap(errStr(err, str)) } } @@ -328,7 +331,7 @@ func checkKafka() (string, error) { str := "the addr is:" + address kafkaClient, err := sarama.NewClient(kafkaAddresses, cfg) if err != nil { - return "", errs.Wrap(err, str) + return "", errs.Wrap(errStr(err, str)) } defer kafkaClient.Close() @@ -378,3 +381,7 @@ func successPrint(s string) { func warningPrint(s string) { colorPrint(colorYellow, "Warning: But %v", s) } + +func errStr(err error, str string) error { + return fmt.Errorf("%v;%s", err, str) +}