introduce a helper for yaml.NewEncoder() to always close it - #2196
Open
omar-polo wants to merge 1 commit into
Open
introduce a helper for yaml.NewEncoder() to always close it#2196omar-polo wants to merge 1 commit into
omar-polo wants to merge 1 commit into
Conversation
omar-polo
force-pushed
the
op/yaml-decoder-close
branch
from
June 9, 2026 12:59
8eb3112 to
3f1adff
Compare
There was a problem hiding this comment.
Pull request overview
This PR introduces a small YAML marshaling helper to ensure yaml.Encoder is always Close()d (to properly flush), and updates call sites to use it so YAML output isn’t silently truncated due to a missed close.
Changes:
- Added
utils.YAMLEncode(io.Writer, any) erroras a single safe entry point for YAML encoding + encoder close. - Replaced direct
yaml.NewEncoder(...).Encode(...)usage withYAMLEncode(...)in config saving and CLI output paths. - Updated imports in affected files to remove direct YAML encoder usage and reference
utilsinstead.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| utils/marshal.go | Adds YAMLEncode helper that encodes and closes the YAML encoder. |
| utils/config_policy.go | Uses YAMLEncode for policy config persistence and YAML dumps. |
| subcommands/service/show.go | Uses utils.YAMLEncode for YAML output of service configuration. |
| subcommands/config/config.go | Uses utils.YAMLEncode for YAML output in config store show path. |
| config/load.go | Uses utils.YAMLEncode when writing config YAML files to disk. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
Author
|
this is still marked as draft as it depends on #2095 to go in first. |
omar-polo
force-pushed
the
op/refactor-config
branch
2 times, most recently
from
June 16, 2026 08:51
55c8597 to
3f5df7a
Compare
omar-polo
force-pushed
the
op/refactor-config
branch
3 times, most recently
from
July 8, 2026 20:20
41b79d3 to
405c2de
Compare
unlike json.NewEncoder(), yaml Encoder needs to be Close()d to properly flush. Introduce an helper and use it across the codebase to avoid forgetting to do so.
omar-polo
marked this pull request as ready for review
July 21, 2026 15:38
omar-polo
force-pushed
the
op/yaml-decoder-close
branch
from
July 21, 2026 15:39
3f1adff to
6ff0e1a
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (2)
config/load.go:168
tmpFile.Close()errors are ignored. If the close fails (e.g., delayed write/FS error), the code may still proceed as if the YAML write succeeded and (in the success path) rename an incompletely flushed file. Capture the close error and treat it like an encode failure before renaming.
err = utils.YAMLEncode(tmpFile, src)
tmpFile.Close()
if err == nil {
err = os.Rename(tmpFile.Name(), file)
utils/config_policy.go:211
tmpFile.Close()errors are ignored. If the close fails, the file may not be fully flushed but the code can still rename it, producing a partial/corrupted policy file. Capture the close error and treat it like an encode failure before renaming.
err = YAMLEncode(tmpFile, c)
tmpFile.Close()
if err == nil {
err = os.Rename(tmpFile.Name(), filename)
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
unlike json.NewEncoder(), yaml Encoder needs to be Close()d to properly flush. Introduce an helper and use it across the codebase to avoid forgetting to do so.