Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add debug logging option #11

Merged
merged 1 commit into from
Aug 27, 2024
Merged

Add debug logging option #11

merged 1 commit into from
Aug 27, 2024

Conversation

AislingHPE
Copy link
Contributor

And fix stdout so nothing except the schema prints (unless there is an error).

Also add debug logging for the reader package, and for validation rules.

Debug: found the following files in "/home/aisling/dev/HewlettPackard/terraschema/test/modules/simple":
        "/home/aisling/dev/HewlettPackard/terraschema/test/modules/simple/main.tf", with variable(s):
        "/home/aisling/dev/HewlettPackard/terraschema/test/modules/simple/variables.tf", with variable(s):
                name
                age
Warning: couldn't apply validation for "age" with condition "var.age > env.age": no translation rules are supported for this condition
Debug: condition located at "/home/aisling/dev/HewlettPackard/terraschema/test/modules/simple/variables.tf:14,21-38"
Debug: the following errors occurred:
        contains([...],var.input_parameter): condition is not a 'contains()' function
        var == "a" || var == "b": operator is not || or ==
        a <>= (variable or variable length) (&& ...): could not evaluate expression as a constant value: /home/aisling/dev/HewlettPackard/terraschema/test/modules/simple/variables.tf:14,31-34: Variables not allowed; Variables may not be used here.
        can(regex("...",var.input_parameter)): rule can only be applied to string types, not "number"
Schema written to "/home/aisling/dev/HewlettPackard/terraschema/schema.json"

@AislingHPE AislingHPE force-pushed the debug-logging branch 5 times, most recently from 6d1dab4 to addf9af Compare August 27, 2024 09:52
@AislingHPE AislingHPE marked this pull request as ready for review August 27, 2024 09:58
And fix stdout so nothing except the schema prints (unless there is an error).

Also add debug logging for the reader package, and for validation rules.

```
Debug: found the following files in "/home/aisling/dev/HewlettPackard/terraschema/test/modules/simple":
        "/home/aisling/dev/HewlettPackard/terraschema/test/modules/simple/main.tf", with variable(s):
        "/home/aisling/dev/HewlettPackard/terraschema/test/modules/simple/variables.tf", with variable(s):
                name
                age
Warning: couldn't apply validation for "age" with condition "var.age > env.age": no translation rules are supported for this condition
Debug: condition located at "/home/aisling/dev/HewlettPackard/terraschema/test/modules/simple/variables.tf:14,21-38"
Debug: the following errors occurred:
        contains([...],var.input_parameter): condition is not a 'contains()' function
        var == "a" || var == "b": operator is not || or ==
        a <>= (variable or variable length) (&& ...): could not evaluate expression as a constant value: /home/aisling/dev/HewlettPackard/terraschema/test/modules/simple/variables.tf:14,31-34: Variables not allowed; Variables may not be used here.
        can(regex("...",var.input_parameter)): rule can only be applied to string types, not "number"
Schema written to "/home/aisling/dev/HewlettPackard/terraschema/schema.json"
```
"unless an error occurs. Overrides 'debug' and 'output.",
)

rootCmd.Flags().BoolVar(&debugOut, "debug", false,
"output debug logs, may useful for troubleshooting issues relating to translating\n"+
"validation rules. Does not work with --stdout",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could send to stderr. But I suspect you're not up for that :-)

@@ -92,8 +86,21 @@ func createNode(name string, v model.TranslatedVariable, options CreateSchemaOpt
if v.Variable.Validation != nil && v.ConditionAsString != nil {
err = parseConditionToNode(v.Variable.Validation.Condition, *v.ConditionAsString, name, &node)
// if an error occurs, log it and continue.
if err != nil {
fmt.Printf("couldn't apply validation for %q with condition %q. Error: %v\n", name, *v.ConditionAsString, err)
if err != nil && !options.SuppressLogging {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having logging configuration affect control flow will work, but there may be a neater way to do the same thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, but slog gives me a headache and this does the job for now

@AislingHPE AislingHPE merged commit 352d694 into main Aug 27, 2024
2 checks passed
@AislingHPE AislingHPE deleted the debug-logging branch August 27, 2024 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants