Skip to content

Commit

Permalink
better err log
Browse files Browse the repository at this point in the history
  • Loading branch information
freeznet committed Sep 29, 2024
1 parent 396d1ee commit 41fb83c
Showing 1 changed file with 49 additions and 12 deletions.
61 changes: 49 additions & 12 deletions pulsar/resource_pulsar_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down

0 comments on commit 41fb83c

Please sign in to comment.