Enhance error handling and metrics tracking in SteamCache
- Introduced a new error handling system with custom error types for better context and clarity in error reporting. - Implemented URL validation to prevent invalid requests and enhance security. - Updated cache key generation functions to return errors, improving robustness in handling invalid inputs. - Added comprehensive metrics tracking for requests, cache hits, misses, and performance metrics, allowing for better monitoring and analysis of the caching system. - Enhanced logging to include detailed metrics and error information for improved debugging and operational insights.
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
// vfs/vfserror/vfserror.go
|
||||
package vfserror
|
||||
|
||||
import "errors"
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Common VFS errors
|
||||
var (
|
||||
@@ -9,4 +12,47 @@ var (
|
||||
ErrInvalidKey = errors.New("vfs: invalid key")
|
||||
ErrAlreadyExists = errors.New("vfs: key already exists")
|
||||
ErrCapacityExceeded = errors.New("vfs: capacity exceeded")
|
||||
ErrCorruptedFile = errors.New("vfs: corrupted file")
|
||||
ErrInvalidSize = errors.New("vfs: invalid size")
|
||||
ErrOperationTimeout = errors.New("vfs: operation timeout")
|
||||
)
|
||||
|
||||
// VFSError represents a VFS-specific error with context
|
||||
type VFSError struct {
|
||||
Op string // Operation that failed
|
||||
Key string // Key that caused the error
|
||||
Err error // Underlying error
|
||||
Size int64 // Size information if relevant
|
||||
}
|
||||
|
||||
// Error implements the error interface
|
||||
func (e *VFSError) Error() string {
|
||||
if e.Key != "" {
|
||||
return fmt.Sprintf("vfs: %s failed for key %q: %v", e.Op, e.Key, e.Err)
|
||||
}
|
||||
return fmt.Sprintf("vfs: %s failed: %v", e.Op, e.Err)
|
||||
}
|
||||
|
||||
// Unwrap returns the underlying error
|
||||
func (e *VFSError) Unwrap() error {
|
||||
return e.Err
|
||||
}
|
||||
|
||||
// NewVFSError creates a new VFS error with context
|
||||
func NewVFSError(op, key string, err error) *VFSError {
|
||||
return &VFSError{
|
||||
Op: op,
|
||||
Key: key,
|
||||
Err: err,
|
||||
}
|
||||
}
|
||||
|
||||
// NewVFSErrorWithSize creates a new VFS error with size context
|
||||
func NewVFSErrorWithSize(op, key string, size int64, err error) *VFSError {
|
||||
return &VFSError{
|
||||
Op: op,
|
||||
Key: key,
|
||||
Size: size,
|
||||
Err: err,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user