-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
6d1dab4
to
addf9af
Compare
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" ```
addf9af
to
bdb8ea0
Compare
"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", |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
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.