Skip to content

introduce a helper for yaml.NewEncoder() to always close it#2196

Draft
omar-polo wants to merge 3 commits into
mainfrom
op/yaml-decoder-close
Draft

introduce a helper for yaml.NewEncoder() to always close it#2196
omar-polo wants to merge 3 commits into
mainfrom
op/yaml-decoder-close

Conversation

@omar-polo

Copy link
Copy Markdown
Contributor

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 added 3 commits June 9, 2026 12:07
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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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) error as a single safe entry point for YAML encoding + encoder close.
  • Replaced direct yaml.NewEncoder(...).Encode(...) usage with YAMLEncode(...) in config saving and CLI output paths.
  • Updated imports in affected files to remove direct YAML encoder usage and reference utils instead.

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.

Comment thread utils/marshal.go
@omar-polo

Copy link
Copy Markdown
Contributor Author

this is still marked as draft as it depends on #2095 to go in first.

@omar-polo
omar-polo force-pushed the op/refactor-config branch 2 times, most recently from 55c8597 to 3f5df7a Compare June 16, 2026 08:51
@omar-polo
omar-polo force-pushed the op/refactor-config branch 3 times, most recently from 41b79d3 to 405c2de Compare July 8, 2026 20:20
Base automatically changed from op/refactor-config to main July 14, 2026 03:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants