Skip to content

fix: preserve final line of config files lacking a trailing newline#1420

Merged
synfinatic merged 1 commit into
mainfrom
fix-newline
Jun 19, 2026
Merged

fix: preserve final line of config files lacking a trailing newline#1420
synfinatic merged 1 commit into
mainfrom
fix-newline

Conversation

@synfinatic

Copy link
Copy Markdown
Owner

GenerateNewFile dropped the last line of a file when it had no trailing newline, because bufio.Reader.ReadString returns a partial line with io.EOF together, and both copy loops exited before writing it.

Fixes #1419

@codecov

codecov Bot commented Jun 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.31%. Comparing base (0a68b41) to head (99979a0).

Files with missing lines Patch % Lines
internal/fileutils/fileedit.go 50.00% 3 Missing and 5 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1420      +/-   ##
==========================================
- Coverage   88.48%   88.31%   -0.16%     
==========================================
  Files          56       56              
  Lines        3767     3781      +14     
==========================================
+ Hits         3333     3339       +6     
- Misses        299      303       +4     
- Partials      135      139       +4     
Flag Coverage Δ
unittests 88.31% <50.00%> (-0.16%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
internal/fileutils/fileedit.go 70.59% <50.00%> (-3.69%) ⬇️

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0a68b41...99979a0. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes a data-loss bug in FileEdit.GenerateNewFile where the final line of a config file could be dropped when the file lacks a trailing newline, ensuring unmanaged content outside the managed # BEGIN_AWS_SSO_CLI / # END_AWS_SSO_CLI block is preserved.

Changes:

  • Update GenerateNewFile to write the final partial line returned alongside io.EOF (both before locating the managed block and when copying the unmanaged tail).
  • Add unit tests covering config files that do not end with a trailing newline (both with and without an existing managed block).
  • Document the fix in CHANGELOG.md.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
internal/fileutils/fileedit.go Writes EOF partial lines so the final unmanaged line isn’t dropped when there’s no trailing newline.
internal/fileutils/fileedit_test.go Adds regression tests for no-trailing-newline inputs.
CHANGELOG.md Notes the bugfix under Unreleased.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/fileutils/fileedit.go
Comment thread internal/fileutils/fileedit_test.go
Comment thread internal/fileutils/fileedit_test.go
GenerateNewFile dropped the last line of a file when it had no trailing
newline, because bufio.Reader.ReadString returns a partial line with
io.EOF together, and both copy loops exited before writing it.

Fixes #1419
@synfinatic synfinatic merged commit 1a38caf into main Jun 19, 2026
8 of 9 checks passed
@synfinatic synfinatic deleted the fix-newline branch June 19, 2026 17:42
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.

setup profiles silently drops final line of ~/.aws/config when file lacks trailing newline

2 participants