@@ -205,16 +205,17 @@ func (i *Info) containerID() string {
205205// mountInfo is the path: "/proc/self/mountinfo"
206206func containerIDFromMountInfo (mountInfo string ) (string , error ) {
207207 mInfoFile , err := os .Open (mountInfo )
208- if err != nil {
209- return "" , fmt .Errorf ("could not read %s: %w" , mountInfo , err )
210- }
211208 defer func (f * os.File , fileName string ) {
212209 closeErr := f .Close ()
213210 if closeErr != nil {
214211 slog .Error ("Unable to close file" , "file" , fileName , "error" , closeErr )
215212 }
216213 }(mInfoFile , mountInfo )
217214
215+ if err != nil {
216+ return "" , fmt .Errorf ("could not read %s: %w" , mountInfo , err )
217+ }
218+
218219 fileScanner := bufio .NewScanner (mInfoFile )
219220 fileScanner .Split (bufio .ScanLines )
220221
@@ -308,15 +309,15 @@ func (i *Info) releaseInfo(ctx context.Context, osReleaseLocation string) (relea
308309
309310func readOsRelease (path string ) (map [string ]string , error ) {
310311 f , err := os .Open (path )
311- if err != nil {
312- return nil , fmt .Errorf ("release file %s is unreadable: %w" , path , err )
313- }
314312 defer func (f * os.File , fileName string ) {
315313 closeErr := f .Close ()
316314 if closeErr != nil {
317315 slog .Error ("Unable to close file" , "file" , fileName , "error" , closeErr )
318316 }
319317 }(f , path )
318+ if err != nil {
319+ return nil , fmt .Errorf ("release file %s is unreadable: %w" , path , err )
320+ }
320321
321322 info , err := parseOsReleaseFile (f )
322323 if err != nil {
0 commit comments