envknob: ensure f is not nil before using it

This PR fixes a panic that I saw in the mac app where
parsing the env file fails but we don't get to see the
error due to the panic of using f.Name()

Fixes #11425

Signed-off-by: Marwan Sulaiman <marwan@tailscale.com>
This commit is contained in:
Marwan Sulaiman 2024-03-15 11:54:42 -04:00 committed by Marwan Sulaiman
parent 08ebac9acb
commit da7c3d1753
1 changed files with 5 additions and 1 deletions

View File

@ -492,7 +492,11 @@ func ApplyDiskConfig() (err error) {
defer func() {
if err != nil {
// Stash away our return error for the healthcheck package to use.
applyDiskConfigErr = fmt.Errorf("error parsing %s: %w", f.Name(), err)
if f != nil {
applyDiskConfigErr = fmt.Errorf("error parsing %s: %w", f.Name(), err)
} else {
applyDiskConfigErr = fmt.Errorf("error applying disk config: %w", err)
}
}
}()