layer: NewStoreFromOptions(): include driver-name in error message

When reading through some bug reports, I noticed that the error-message for
unsupported storage drivers is not very informative, as it does not include
the actual storage driver. Some of these errors are used as sentinel errors
internally, so improving the error returned by graphdriver.New() may need
some additional work, but this patch makes a start by including the name
of the graphdriver (if set) in the error-message.

Before this patch:

    dockerd --storage-driver=foobar
    ...
    failed to start daemon: error initializing graphdriver: driver not supported

With this patch:

    dockerd --storage-driver=foobar
    ...
    failed to start daemon: error initializing graphdriver: driver not supported: foobar

It's worth noting that there may be code "in the wild" that perform string-
matching on this error (e.g. [balena][1]), which is why I included the name as a separate "component"
in the output, to allow matching parts of the error.

[1]: 3d5c77a466/lib/preload.ts (L34-L35)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-02-01 10:42:05 +01:00
parent 293c814688
commit 22f303e422
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C

View file

@ -62,6 +62,9 @@ func NewStoreFromOptions(options StoreOptions) (Store, error) {
ExperimentalEnabled: options.ExperimentalEnabled,
})
if err != nil {
if options.GraphDriver != "" {
return nil, fmt.Errorf("error initializing graphdriver: %v: %s", err, options.GraphDriver)
}
return nil, fmt.Errorf("error initializing graphdriver: %v", err)
}
logrus.Debugf("Initialized graph driver %s", driver)