Skip to content

fix🐛: return FileCreate's error instead of ending the process - #160

Merged
wenjianzhang merged 1 commit into
mainfrom
fix/file-create-error
Sep 27, 2026
Merged

wenjianzhang merged 1 commit into
mainfrom
fix/file-create-error

Conversation

@wenjianzhang

Copy link
Copy Markdown
Member

pkg.FileCreate returned nothing. It logged a failed create or write, and when the file could not be created it deferred Close on the nil file, which failed and called log.Fatalln: writing into a missing directory ended the process.

It now returns the error from creating, writing or closing the file (os.WriteFile, same flags and mode as before).

Compatibility: callers that call it as a statement keep compiling unchanged. Only code that stores it in a func(bytes.Buffer, string) variable needs updating.

Tests: writes content, truncates an existing file, and reports a file that cannot be created. Counterproof: with the previous body restored behind the new signature, the last test's process exits through log.Fatalln; with a body that drops the error, it fails its assertion.

Copilot AI lite review requested due to automatic review settings September 27, 2026 05:51

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

FileCreate returned nothing. It logged a failed create or write, and when
the file could not be created it deferred Close on the nil file, which
failed and called log.Fatalln: a missing directory ended the whole
process, including a server that called it from a request.

It now returns the error from creating, writing or closing the file.
Callers that call it as a statement keep compiling.
@wenjianzhang
wenjianzhang merged commit 004376f into main Sep 27, 2026
5 checks passed
@wenjianzhang
wenjianzhang deleted the fix/file-create-error branch September 27, 2026 06:00
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.

2 participants