Handle Invalid RC Files #622
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Should fix the issue reported in discord: https://discord.com/channels/1085077079697150023/1086092225122926614/1216673781691711509
The only way I was able to reproduce the failure reported there was to add multiple empty newlines to the
.guardrailsrc
file manually. Since both reporters of this issue were using Windows I assume it has to do with differences in howreadlines
works between different operating systems. The current fix first filters out any empty lines, then asserts that each line has a key and a value before trying to deconstruct them for assignment. If we still somehow encounter a line with only one item in the tuple after splitting on=
, we log a warning and move on. This should reveal any other issues and allow the end user to both debug on their own and include more information when reporting any issues.Also, since we are now using the logger in the Credentials class which is shared between the cli and library, I send the logger via dependency injection so that we can use the appropriate logger based on the situation. After fixing this, tests regarding multi-processing started failing. I'm not completely sure why these changes triggered those failures, but the root cause of the failures were duplicated logs hence the removal on line 299 of validator_service. I also updated the failing test to be more clear what instances we're comparing in the assertions.
[EDIT]: Forgot to add that this PR also reduces the number of times we're loading credentials from the rc file during the Guard/validation lifecycle. As part of that, I also defaulted to disabling the tracer if not specified. @zsimjee this would make our anonymous metrics opt-in instead of opt-out.