terraform-provider-bigip icon indicating copy to clipboard operation
terraform-provider-bigip copied to clipboard

Error handling and log messages is not unified/aligned

Open dannyk81 opened this issue 6 years ago • 0 comments

I've been going over our error handling practices and some of the log messages and I think we need to have some alignment, especially with Terraform's best practices:

  1. Error checking should be done on aggregate types only (schema.TypeList, schema.TypeSet, and schema.TypeMap) reference: https://www.terraform.io/docs/extend/best-practices/detecting-drift.html#error-checking-aggregate-types

  2. In case of error in a Set operations or any other action we need to use return fmt.Errorf() method with a short description of the error that occurred, affected resource and the error content, for example:

return fmt.Errorf("error getting resource %s: %v", d.Id(), err)

Currently, we use log.Printf() and return err which is not a very good way to handle this, since the log message is suppressed and the err returned lacks context.

  1. Logging of debug messages we wish to add throughout the code, should use log.Printf() (if formatting is required) or log.Println() (if there's no formatting) and be tagged as [DEBUG], but this should not be used in error contexts.

I will try to work on a PR to align with these practices.

/cc @scshitole

dannyk81 avatar Sep 27 '18 19:09 dannyk81