introduce a helper for yaml.NewEncoder() to always close it#2196
Draft
omar-polo wants to merge 3 commits into
Draft
introduce a helper for yaml.NewEncoder() to always close it#2196omar-polo wants to merge 3 commits into
omar-polo wants to merge 3 commits into
Conversation
no reason to splatter the code for the configuration handling among different packages, try to regroup everything under config.
for string, numbers and boolean it's the same behaviour; now it could stringify other types that before were yielding only "", but shouldn't matter much here. Also, no need to special case strings since it's not a performance-sensitive part, and the gained readability matters.
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
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
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.