Improve error message to include expected network label

Updated the error message when a network is found with an incorrect label to also display the expected label value. This provides more context for debugging.

Signed-off-by: divinity76 <hans@loltek.net>
This commit is contained in:
divinity76 2024-10-15 14:31:50 +02:00 committed by Nicolas De loof
parent 38e3d670a9
commit 0cbb73c024
1 changed files with 7 additions and 1 deletions

View File

@ -1208,7 +1208,13 @@ func (s *composeService) resolveOrCreateNetwork(ctx context.Context, n *types.Ne
"Set `external: true` to use an existing network", n.Name, expectedProjectLabel)
}
if inspect.Labels[api.NetworkLabel] != expectedNetworkLabel {
return fmt.Errorf("network %s was found but has incorrect label %s set to %q", n.Name, api.NetworkLabel, inspect.Labels[api.NetworkLabel])
return fmt.Errorf(
"network %s was found but has incorrect label %s set to %q (expected: %q)",
n.Name,
api.NetworkLabel,
inspect.Labels[api.NetworkLabel],
expectedNetworkLabel,
)
}
return nil
}