plugin-barman-cloud/internal/cnpgi/common/errors.go
Leonardo Cecchi 08c3f1c232
feat: return proper gRPC error codes for expected conditions (#549)
The plugin now returns a 404 status code when a requested WAL file does
not exist in the object store.

This prevents misleading log entries such as "Error while handling gRPC
request" for expected missing-file scenarios.

The `ErrEndOfWALStreamReached` now returns `OutOfRange` error.

The `ErrMissingPermissions` now returns `FailedPrecondition` error.

Signed-off-by: Leonardo Cecchi <leonardo.cecchi@enterprisedb.com>
Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
Signed-off-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com>
Co-authored-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
Co-authored-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com>
2025-09-25 10:36:48 +02:00

26 lines
938 B
Go

package common
import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
// ErrEndOfWALStreamReached is returned when end of WAL is detected in the cloud archive.
var ErrEndOfWALStreamReached = status.Errorf(codes.OutOfRange, "end of WAL reached")
// ErrMissingPermissions is raised when the sidecar has no
// permission to download the credentials needed to reach
// the object storage.
// This will be fixed by the reconciliation loop in the
// operator plugin.
var ErrMissingPermissions = status.Errorf(codes.FailedPrecondition,
"no permission to download the backup credentials, retrying")
// newWALNotFoundError returns a error that states that a
// certain WAL file has not been found. This error is
// compatible with GRPC status codes, resulting in a 404
// being used as a response code.
func newWALNotFoundError(walName string) error {
return status.Errorf(codes.NotFound, "wal %q not found", walName)
}