feat: return 404 for missing WAL files

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.

Signed-off-by: Leonardo Cecchi <leonardo.cecchi@enterprisedb.com>
This commit is contained in:
Leonardo Cecchi 2025-09-24 06:51:23 +02:00 committed by Marco Nenciarini
parent 65a0d11ec8
commit e5a0aeed34
2 changed files with 14 additions and 14 deletions

View File

@ -1,16 +1,14 @@
package common
// walNotFoundError is raised when a WAL file has not been found in the object store
type walNotFoundError struct{}
import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func newWALNotFoundError() *walNotFoundError { return &walNotFoundError{} }
// ShouldPrintStackTrace tells whether the sidecar log stream should contain the stack trace
func (e walNotFoundError) ShouldPrintStackTrace() bool {
return false
}
// Error implements the error interface
func (e walNotFoundError) Error() string {
return "WAL file not found"
// 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)
}

View File

@ -18,6 +18,8 @@ import (
"github.com/cloudnative-pg/machinery/pkg/fileutils"
walUtils "github.com/cloudnative-pg/machinery/pkg/fileutils/wals"
"github.com/cloudnative-pg/machinery/pkg/log"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
@ -350,7 +352,7 @@ func (w WALServiceImplementation) restoreFromBarmanObjectStore(
// The failure has already been logged in walRestorer.RestoreList method
if walStatus[0].Err != nil {
if errors.Is(walStatus[0].Err, barmanRestorer.ErrWALNotFound) {
return newWALNotFoundError()
return newWALNotFoundError(walStatus[0].WalName)
}
return walStatus[0].Err
@ -458,7 +460,7 @@ func gatherWALFilesToRestore(walName string, parallel int) (walList []string, er
}
// ErrEndOfWALStreamReached is returned when end of WAL is detected in the cloud archive.
var ErrEndOfWALStreamReached = errors.New("end of WAL reached")
var ErrEndOfWALStreamReached = status.Errorf(codes.NotFound, "end of WAL reached")
// checkEndOfWALStreamFlag returns ErrEndOfWALStreamReached if the flag is set in the restorer.
func checkEndOfWALStreamFlag(walRestorer *barmanRestorer.WALRestorer) error {