Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle error in retainLogs #3687

Merged
merged 1 commit into from
Jun 28, 2024
Merged

handle error in retainLogs #3687

merged 1 commit into from
Jun 28, 2024

Conversation

wjordan
Copy link
Contributor

@wjordan wjordan commented Jun 28, 2024

filepath.Walk() may return an unhandled err (for some separate issue with the directory), causing a 'nil pointer dereference' panic because info is nil in this case.

We want to handle the error by returning it, instead of a panic.

Example stacktrace
panic: runtime error: invalid memory address or nil pointer dereference
panic({0x10618bb20?, 0x107546d10?})
        runtime/panic.go:770 +0x124
github.com/superfly/flyctl/internal/logger/logfile.retainLogs.func1({0x14000a0e140, 0x3b}, {0x0, 0x0}, {0x140001bf068?, 0x16?})
        github.com/superfly/flyctl/internal/logger/logfile/fs.go:49 +0xa4
path/filepath.walk({0x140001bf068, 0x16}, {0x1064b5ba8, 0x14000121930}, 0x1400079dae8)
        path/filepath/path.go:498 +0x16c
path/filepath.Walk({0x140001bf068, 0x16}, 0x1400079dae8)
        path/filepath/path.go:560 +0x6c
github.com/superfly/flyctl/internal/logger/logfile.retainLogs({0x140001bf068?, 0x3b?})
        github.com/superfly/flyctl/internal/logger/logfile/fs.go:48 +0x44
github.com/superfly/flyctl/internal/logger/logfile.CreateLogFile()
        github.com/superfly/flyctl/internal/logger/logfile/fs.go:95 +0x84
github.com/superfly/flyctl/internal/logger.InitLogFile()
        github.com/superfly/flyctl/internal/logger/global_logfile.go:17 +0x28
github.com/superfly/flyctl/internal/cli.Run({0x1064aea90?, 0x14000ab4580?}, 0x14000488140, {0x140001e0010, 0xa, 0xa})
        github.com/superfly/flyctl/internal/cli/cli.go:46 +0x7c
main.run()
        github.com/superfly/flyctl/main.go:47 +0x174
main.main()
        github.com/superfly/flyctl/main.go:26 +0x20

filepath.Walk() may return an error that was not handled,
causing a panic on nil pointer dereference because
`info` would be `nil`.
@wjordan wjordan added the bug Something isn't working label Jun 28, 2024
@wjordan wjordan merged commit 9caf7a7 into master Jun 28, 2024
34 checks passed
@wjordan wjordan deleted the retainLogs-handle-err branch June 28, 2024 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants