Skip to content

refactor: use log.Fatal for fatal error handling in main#539

Merged
tenthirtyam merged 1 commit intomainfrom
refactor/standardize-fatal-error-handling
Jun 5, 2025
Merged

refactor: use log.Fatal for fatal error handling in main#539
tenthirtyam merged 1 commit intomainfrom
refactor/standardize-fatal-error-handling

Conversation

@tenthirtyam
Copy link
Copy Markdown
Collaborator

Refactor fatal error handling in the main function to use log.Fatal.

Previously, fatal errors were handled by printing to os.Stderr using fmt.Fprintln followed by an explicit os.Exit(1).This change replaces that pattern with a single call to log.Fatal(err). This is more idiomatic Go, makes the code more concise, and leverages the standard log package's capabilities, such as automatic timestamping of the error message. The program's exit behavior (exiting with status 1 on fatal error) remains the same.

~/Downloads/packer-plugin-vsphere git:[refactor/standardize-fatal-error-handling]
go fmt ./...

~/Downloads/packer-plugin-vsphere git:[refactor/standardize-fatal-error-handling]
make dev
packer plugins install --path packer-plugin-vsphere "github.com/hashicorp/vsphere"
Successfully installed plugin github.com/hashicorp/vsphere from /Users/johnsonryan/Downloads/packer-plugin-vsphere/packer-plugin-vsphere to /Users/johnsonryan/.packer.d/plugins/github.com/hashicorp/vsphere/packer-plugin-vsphere_v1.4.3-dev_x5.0_darwin_amd64

~/Downloads/packer-plugin-vsphere git:[refactor/standardize-fatal-error-handling]
make build

~/Downloads/packer-plugin-vsphere git:[refactor/standardize-fatal-error-handling]
make test
?       github.com/hashicorp/packer-plugin-vsphere      [no test files]
?       github.com/hashicorp/packer-plugin-vsphere/builder/vsphere/common/testing       [no test files]
?       github.com/hashicorp/packer-plugin-vsphere/builder/vsphere/common/utils [no test files]
ok      github.com/hashicorp/packer-plugin-vsphere/builder/vsphere/clone        2.518s
?       github.com/hashicorp/packer-plugin-vsphere/examples/driver      [no test files]
?       github.com/hashicorp/packer-plugin-vsphere/version      [no test files]
ok      github.com/hashicorp/packer-plugin-vsphere/builder/vsphere/common       7.563s
ok      github.com/hashicorp/packer-plugin-vsphere/builder/vsphere/driver       12.648s
ok      github.com/hashicorp/packer-plugin-vsphere/builder/vsphere/iso  4.505s
ok      github.com/hashicorp/packer-plugin-vsphere/builder/vsphere/supervisor   11.146s
ok      github.com/hashicorp/packer-plugin-vsphere/post-processor/vsphere       3.065s
ok      github.com/hashicorp/packer-plugin-vsphere/post-processor/vsphere-template      6.042s

@tenthirtyam tenthirtyam added this to the v2.0.0 milestone May 23, 2025
@tenthirtyam tenthirtyam self-assigned this May 23, 2025
@tenthirtyam tenthirtyam requested a review from a team as a code owner May 23, 2025 18:48
@tenthirtyam tenthirtyam added technical-debt Technical Debt refactor Refactor labels May 23, 2025
Refactor fatal error handling in the main function to use `log.Fatal`.

Previously, fatal errors were handled by printing to os.Stderr using `fmt.Fprintln` followed by an explicit `os.Exit(1)`.This change replaces that pattern with a single call to `log.Fatal(err)`. This is more idiomatic Go, makes the code more concise, and leverages the standard log package's capabilities, such as automatic timestamping of the error message. The program's exit behavior (exiting with status 1 on fatal error) remains the same.

Signed-off-by: Ryan Johnson <ryan.johnson@broadcom.com>
@tenthirtyam tenthirtyam force-pushed the refactor/standardize-fatal-error-handling branch from 1127b34 to 72efb46 Compare May 23, 2025 21:56
Copy link
Copy Markdown
Contributor

@kp2099 kp2099 left a comment

Choose a reason for hiding this comment

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

LGTM

@tenthirtyam tenthirtyam merged commit 16a1934 into main Jun 5, 2025
13 checks passed
@tenthirtyam tenthirtyam deleted the refactor/standardize-fatal-error-handling branch June 5, 2025 14:34
@github-actions
Copy link
Copy Markdown

I'm going to lock this pull request because it has been closed for 30 days. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 29, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

refactor Refactor technical-debt Technical Debt

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants