Skip to content

fix: handle stat errors in file helpers#10084

Open
immanuwell wants to merge 1 commit into
GoogleContainerTools:mainfrom
immanuwell:fix-util-stat-errors
Open

fix: handle stat errors in file helpers#10084
immanuwell wants to merge 1 commit into
GoogleContainerTools:mainfrom
immanuwell:fix-util-stat-errors

Conversation

@immanuwell
Copy link
Copy Markdown

Description
IsFile and IsDir assumed os.Stat always returns FileInfo unless the path is missing. But file/child, where file is a regular file, returns a stat error and nil info, so the old code panics.

This returns false on any stat error, same vibe as "not a file/dir". tiny fix, low-key useful.

Repro:

  1. create a regular file
  2. call IsFile("<tmp>/file/child") or IsDir("<tmp>/file/child")
  3. before: nil pointer panic in IsFile/IsDir
  4. after: returns false

User facing changes
No CLI output changes, just avoids a crash for bad local paths.

Testing

  • go test ./pkg/skaffold/util -run 'TestIsFileIsDir|TestIsFileIsDirStatError'\n- go test ./pkg/skaffold/util\n- make quicktest

@immanuwell immanuwell requested a review from a team as a code owner May 15, 2026 14:01
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the IsFile and IsDir utility functions to simplify error handling, ensuring they return false on any os.Stat error. A new test case is also included to verify this behavior. The reviewer recommends adding documentation comments to these exported functions to align with Go best practices.

Comment thread pkg/skaffold/util/util.go
@@ -267,14 +267,18 @@ func AbsolutePaths(workspace string, paths []string) []string {

func IsFile(path string) bool {
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.

medium

Exported functions should have a documentation comment according to Go best practices. This provides clarity on the function's behavior, such as whether it follows symlinks and how it handles errors.

Suggested change
func IsFile(path string) bool {
// IsFile returns true if the path exists and is a regular file. Symlinks are followed.
func IsFile(path string) bool {
References
  1. All exported names should have a doc comment. This is a standard practice in Go to improve code maintainability and discoverability. (link)

Comment thread pkg/skaffold/util/util.go
return info.Mode().IsRegular()
}

func IsDir(path string) bool {
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.

medium

Exported functions should have a documentation comment according to Go best practices. This clarifies that the function follows symlinks and returns false on any error.

Suggested change
func IsDir(path string) bool {
// IsDir returns true if the path exists and is a directory. Symlinks are followed.
func IsDir(path string) bool {
References
  1. All exported names should have a doc comment. This is a standard practice in Go to improve code maintainability and discoverability. (link)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant