From 41fb83c8b2d8f1b34a4b4e7395e538c63052e201 Mon Sep 17 00:00:00 2001 From: Rui Fu Date: Sun, 29 Sep 2024 14:16:46 +0800 Subject: [PATCH] better err log --- pulsar/resource_pulsar_function.go | 61 ++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 12 deletions(-) diff --git a/pulsar/resource_pulsar_function.go b/pulsar/resource_pulsar_function.go index 7a3615f..fcdfe8a 100644 --- a/pulsar/resource_pulsar_function.go +++ b/pulsar/resource_pulsar_function.go @@ -395,7 +395,11 @@ func resourcePulsarFunctionRead(ctx context.Context, d *schema.ResourceData, met return diag.FromErr(errors.Wrapf(err, "failed to get function %s", d.Id())) } - unmarshalFunctionConfig(functionConfig, d) + err = unmarshalFunctionConfig(functionConfig, d) + if err != nil { + tflog.Debug(ctx, fmt.Sprintf("@@@Read function: %v", err)) + return diag.Errorf("ERROR_UNMARSHAL_FUNCTION_CONFIG: %v", err) + } return nil } @@ -675,19 +679,31 @@ func marshalFunctionConfig(d *schema.ResourceData) (*utils.FunctionConfig, error func unmarshalFunctionConfig(functionConfig utils.FunctionConfig, d *schema.ResourceData) error { if functionConfig.Jar != nil { - d.Set(resourceFunctionJarKey, *functionConfig.Jar) + err := d.Set(resourceFunctionJarKey, *functionConfig.Jar) + if err != nil { + return err + } } if functionConfig.Py != nil { - d.Set(resourceFunctionPyKey, *functionConfig.Py) + err := d.Set(resourceFunctionPyKey, *functionConfig.Py) + if err != nil { + return err + } } if functionConfig.Go != nil { - d.Set(resourceFunctionGoKey, *functionConfig.Go) + err := d.Set(resourceFunctionGoKey, *functionConfig.Go) + if err != nil { + return err + } } if functionConfig.ClassName != "" { - d.Set(resourceFunctionClassNameKey, functionConfig.ClassName) + err := d.Set(resourceFunctionClassNameKey, functionConfig.ClassName) + if err != nil { + return err + } } if len(functionConfig.Inputs) != 0 { @@ -701,31 +717,52 @@ func unmarshalFunctionConfig(functionConfig utils.FunctionConfig, d *schema.Reso } if functionConfig.TopicsPattern != nil { - d.Set(resourceFunctionTopicsPatternKey, *functionConfig.TopicsPattern) + err := d.Set(resourceFunctionTopicsPatternKey, *functionConfig.TopicsPattern) + if err != nil { + return err + } } if functionConfig.Parallelism != 0 { - d.Set(resourceFunctionParallelismKey, functionConfig.Parallelism) + err := d.Set(resourceFunctionParallelismKey, functionConfig.Parallelism) + if err != nil { + return err + } } if functionConfig.Output != "" { - d.Set(resourceFunctionOutputKey, functionConfig.Output) + err := d.Set(resourceFunctionOutputKey, functionConfig.Output) + if err != nil { + return err + } } if functionConfig.Parallelism != 0 { - d.Set(resourceFunctionParallelismKey, functionConfig.Parallelism) + err := d.Set(resourceFunctionParallelismKey, functionConfig.Parallelism) + if err != nil { + return err + } } if functionConfig.ProcessingGuarantees != "" { - d.Set(resourceFunctionProcessingGuaranteesKey, functionConfig.ProcessingGuarantees) + err := d.Set(resourceFunctionProcessingGuaranteesKey, functionConfig.ProcessingGuarantees) + if err != nil { + return err + } } if functionConfig.SubName != "" { - d.Set(resourceFunctionSubscriptionNameKey, functionConfig.SubName) + err := d.Set(resourceFunctionSubscriptionNameKey, functionConfig.SubName) + if err != nil { + return err + } } if functionConfig.SubscriptionPosition != "" { - d.Set(resourceFunctionSubscriptionPositionKey, functionConfig.SubscriptionPosition) + err := d.Set(resourceFunctionSubscriptionPositionKey, functionConfig.SubscriptionPosition) + if err != nil { + return err + } } err := d.Set(resourceFunctionCleanupSubscriptionKey, functionConfig.CleanupSubscription)