From 92d2e12a4d1f2886dac5d202694c89f628ef2134 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 24 Aug 2022 18:20:29 +0200 Subject: [PATCH] daemon: getInspectData(): reduce cyclomatic complexity Use an early return if looking up metadata fails. Signed-off-by: Sebastiaan van Stijn --- daemon/inspect.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/daemon/inspect.go b/daemon/inspect.go index d1525edd26..3fc3de2806 100644 --- a/daemon/inspect.go +++ b/daemon/inspect.go @@ -197,17 +197,16 @@ func (daemon *Daemon) getInspectData(container *container.Container) (*types.Con } graphDriverData, err := container.RWLayer.Metadata() - // If container is marked as Dead, the container's graphdriver metadata - // could have been removed, it will cause error if we try to get the metadata, - // we can ignore the error if the container is dead. if err != nil { - if !container.Dead { - return nil, errdefs.System(err) + if container.Dead { + // container is marked as Dead, and its graphDriver metadata may + // have been removed; we can ignore errors. + return contJSONBase, nil } - } else { - contJSONBase.GraphDriver.Data = graphDriverData + return nil, errdefs.System(err) } + contJSONBase.GraphDriver.Data = graphDriverData return contJSONBase, nil }