Skip to content

Commit

Permalink
[runsc] Print file name when cannot load state file
Browse files Browse the repository at this point in the history
When `runsc` does not work, there are messages like

```
loading container: file does not exist
...
loading sandbox: file does not exist
```

The problem here is, there is no indication of file path, making it harder to debug.

I don't have access to environment where these errors appear, so I cannot repro. Better diagnostics would help.

There's a comment in code suggesting that error code is important, so we cannot modify error IIUC

https://github.com/google/gvisor/blob/9c490f813d37882f0374b7aebdad9961277623b8/runsc/container/state_file.go#L81

so my suggestion is to log the file name.

FUTURE_COPYBARA_INTEGRATE_REVIEW=#11457 from stepancheg:state-file f0ac6d5
PiperOrigin-RevId: 725255102
  • Loading branch information
stepancheg authored and gvisor-bot committed Feb 12, 2025
1 parent 95ad423 commit 6b158ce
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion runsc/container/state_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,12 @@ func (s *StateFile) load(v any, opts LoadOpts) error {
}
defer s.UnlockOrDie()

metaBytes, err := os.ReadFile(s.statePath())
path := s.statePath()
metaBytes, err := os.ReadFile(path)
if err != nil {
// Caller of this function relies on error code, we cannot return new error,
// but we need to provide a message with file name.
log.Warningf("Error loading state file %q: %v", path, err)
return err
}
return json.Unmarshal(metaBytes, &v)
Expand Down

0 comments on commit 6b158ce

Please sign in to comment.