mirror of
https://github.com/mudler/LocalAI.git
synced 2026-06-05 23:36:49 -04:00
Replace the controller-side error-string match with a shared, code-aware helper. Go error types don't survive the gRPC boundary, so the signal is carried as a status code (FailedPrecondition): - pkg/grpc/grpcerrors: ModelNotLoaded(backend) constructor + IsModelNotLoaded(err) checker (status-code first, message fallback for backends not yet migrated). - InFlightTrackingClient.reconcile now uses grpcerrors.IsModelNotLoaded. - Migrate the Go backends that emit this error (parakeet-cpp, cloud-proxy, rfdetr-cpp) to the typed constructor. Acting on a false positive is harmless (the model is just reloaded). Assisted-by: Claude:claude-opus-4-8 go vet Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
36 lines
1.3 KiB
Go
36 lines
1.3 KiB
Go
// Package grpcerrors defines well-known error signals shared between backends
|
|
// (which produce them) and the router (which consumes them). Go error types do
|
|
// not survive the gRPC boundary, so these conditions are carried as gRPC status
|
|
// codes and detected via the code rather than by matching the error message.
|
|
package grpcerrors
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
)
|
|
|
|
// ModelNotLoaded returns the canonical error a backend returns when it has no
|
|
// model loaded for the request. It carries codes.FailedPrecondition so callers
|
|
// can detect it across the gRPC boundary without matching the message string.
|
|
func ModelNotLoaded(backend string) error {
|
|
return status.Errorf(codes.FailedPrecondition, "%s: model not loaded", backend)
|
|
}
|
|
|
|
// IsModelNotLoaded reports whether err signals that the backend has no model
|
|
// loaded. It prefers the typed gRPC status code (FailedPrecondition) and falls
|
|
// back to the message for backends that have not yet adopted ModelNotLoaded.
|
|
//
|
|
// Acting on a false positive is harmless: the only consequence upstream is that
|
|
// the model is reloaded, which is idempotent.
|
|
func IsModelNotLoaded(err error) bool {
|
|
if err == nil {
|
|
return false
|
|
}
|
|
if status.Code(err) == codes.FailedPrecondition {
|
|
return true
|
|
}
|
|
return strings.Contains(strings.ToLower(err.Error()), "model not loaded")
|
|
}
|