compute-sdk-go
compute-sdk-go copied to clipboard
configstore: no error when opening a config store that does not exist
In the following sample code, no error is returned from configstore.Open("DOES_NOT_EXIST"), but a configstore.ErrStoreNotFound error is returned from cs.Get("cat").
cs, err := configstore.Open("DOES_NOT_EXIST") // err == nil
switch {
case errors.Is(err, configstore.ErrStoreNotFound):
fsthttp.Error(w, "config store not found: configstore.Open", fsthttp.StatusNotFound)
return
case err != nil:
fsthttp.Error(w, fmt.Sprintf("error opening config store: %s", err.Error()), fsthttp.StatusInternalServerError)
return
}
v, err := cs.Get("cat") // err == configstore.ErrStoreNotFound
switch {
case errors.Is(err, configstore.ErrStoreNotFound):
fsthttp.Error(w, "config store not found: cs.Get", fsthttp.StatusNotFound)
return
case errors.Is(err, configstore.ErrKeyNotFound):
fsthttp.Error(w, "config store key not found", fsthttp.StatusNotFound)
return
case err != nil:
fsthttp.Error(w, fmt.Sprintf("error opening config store key: %s", err.Error()), fsthttp.StatusInternalServerError)
return
}
To better match the Rust SDK, and to provide a better user experience, consider returning a configstore.ErrStoreNotFound from configstore.Open when the named config store does not exist.
Possibly related: #118