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

[parser/scenarios] defer yaml file closure #2689

Merged
merged 4 commits into from Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion pkg/leakybucket/manager_load.go
Expand Up @@ -198,6 +198,7 @@
log.Errorf("Can't access leaky configuration file %s", f)
return nil, nil, err
}
defer bucketConfigurationFile.Close()
dec := yaml.NewDecoder(bucketConfigurationFile)
dec.SetStrict(true)
for {
Expand All @@ -224,7 +225,7 @@
}
ok, err := cwversion.Satisfies(bucketFactory.FormatVersion, cwversion.Constraint_scenario)
if err != nil {
log.Fatalf("Failed to check version : %s", err)
return nil, nil, fmt.Errorf("failed to check version : %s", err)

Check warning on line 228 in pkg/leakybucket/manager_load.go

View check run for this annotation

Codecov / codecov/patch

pkg/leakybucket/manager_load.go#L228

Added line #L228 was not covered by tests
}
if !ok {
log.Errorf("can't load %s : %s doesn't satisfy scenario format %s, skip", bucketFactory.Name, bucketFactory.FormatVersion, cwversion.Constraint_scenario)
Expand Down
5 changes: 3 additions & 2 deletions pkg/parser/stage.go
Expand Up @@ -57,6 +57,7 @@
if err != nil {
return nil, fmt.Errorf("can't access parsing configuration file %s : %s", stageFile.Filename, err)
}
defer yamlFile.Close()
//process the yaml
dec := yaml.NewDecoder(yamlFile)
dec.SetStrict(true)
Expand All @@ -70,7 +71,7 @@
log.Tracef("End of yaml file")
break
}
log.Fatalf("Error decoding parsing configuration file '%s': %v", stageFile.Filename, err)
return nil, fmt.Errorf("error decoding parsing configuration file '%s': %v", stageFile.Filename, err)

Check warning on line 74 in pkg/parser/stage.go

View check run for this annotation

Codecov / codecov/patch

pkg/parser/stage.go#L74

Added line #L74 was not covered by tests
}

//check for empty bucket
Expand All @@ -85,7 +86,7 @@
}
ok, err := cwversion.Satisfies(node.FormatVersion, cwversion.Constraint_parser)
if err != nil {
log.Fatalf("Failed to check version : %s", err)
return nil, fmt.Errorf("failed to check version : %s", err)

Check warning on line 89 in pkg/parser/stage.go

View check run for this annotation

Codecov / codecov/patch

pkg/parser/stage.go#L89

Added line #L89 was not covered by tests
}
if !ok {
log.Errorf("%s : %s doesn't satisfy parser format %s, skip", node.Name, node.FormatVersion, cwversion.Constraint_parser)
Expand Down