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

Fix: passing a non-JSON string to terratag should not panic #123

Merged
merged 2 commits into from
Apr 24, 2022

Conversation

TomerHeber
Copy link
Collaborator

Print a log message and exit(1) instead.

➜  tf git:(fix-invalid-json-not-panic-#120) ✗ ../terratag -tags='fsdfsdfsdfds' -rename=false -dir=.
2022/04/21 07:10:39 [INFO] Processing file main.tf
2022/04/21 07:10:39 [ERROR] Invalid input tags! must be a valid JSON.
Input: fsdfsdfsdfds
Error: invalid character 's' in literal false (expecting 'a')
➜  tf git:(fix-invalid-json-not-panic-#120) ✗ echo $?
1

main.go Outdated
if err != nil {
log.Printf("[ERROR] Invalid input tags! must be a valid JSON.\nInput: %s\nError: %s\n", tags, err.Error())
os.Exit(1)
}
PanicOnError(err, nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this make this line redundant?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@yaronya - yes. thanks for pointing it out. Removed.

@@ -162,7 +162,10 @@ func tagFileResources(path string, dir string, filter string, tags string, tfVer
func jsonToHclMap(tags string) string {
var tagsMap map[string]string
err := json.Unmarshal([]byte(tags), &tagsMap)
PanicOnError(err, nil)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

line removed....

@TomerHeber TomerHeber force-pushed the fix-invalid-json-not-panic-#120 branch from ca247fd to f1ce56e Compare April 24, 2022 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants