Documentation
¶
Overview ¶
Package errors provides custom error types for the starmap system. These errors enable better error handling, programmatic error checking, and improved debugging throughout the application.
Example ¶
Example shows basic error creation and checking.
package main
import (
"fmt"
"github.com/agentstation/starmap/pkg/errors"
)
func main() {
// Create a not found error
err := &errors.NotFoundError{
Resource: "model",
ID: "gpt-5",
}
// Check error type
if errors.IsNotFound(err) {
fmt.Println("Resource not found")
}
}
Output: Resource not found
Example (APIError) ¶
Example_aPIError shows API error handling.
package main
import (
"fmt"
"github.com/agentstation/starmap/pkg/errors"
)
func main() {
// Simulate an API error
err := &errors.APIError{
Provider: "openai",
Endpoint: "https://api.openai.com/v1/models",
StatusCode: 429,
Message: "Rate limit exceeded",
}
// Check and handle specific error types
switch err.StatusCode {
case 429:
fmt.Println("Rate limited - retry later")
case 401:
fmt.Println("Authentication failed")
case 500:
fmt.Println("Server error")
}
}
Output: Rate limited - retry later
Example (AuthenticationError) ¶
Example_authenticationError shows authentication error handling.
package main
import (
"fmt"
"github.com/agentstation/starmap/pkg/errors"
)
func main() {
// Create authentication error
err := &errors.AuthenticationError{
Provider: "anthropic",
Message: "API key not configured",
}
// Auth error is already typed
fmt.Printf("Auth failed for %s: %s\n",
err.Provider, err.Message)
}
Output: Auth failed for anthropic: API key not configured
Example (ErrorChaining) ¶
Example_errorChaining shows chained error handling.
package main
import (
"fmt"
"github.com/agentstation/starmap/pkg/errors"
)
func main() {
// Create a chain of errors
baseErr := &errors.NotFoundError{
Resource: "file",
ID: "config.json",
}
parseErr := &errors.ParseError{
Format: "json",
File: "config.json",
Message: "Failed to parse config",
Err: baseErr,
}
// Check through the chain using standard library
if parseErr.Err != nil {
if _, ok := parseErr.Err.(*errors.NotFoundError); ok {
fmt.Println("File not found in parse chain")
}
}
}
Output: File not found in parse chain
Example (ErrorRecovery) ¶
Example_errorRecovery shows error recovery strategies.
package main
import (
"fmt"
"log"
"time"
"github.com/agentstation/starmap/pkg/errors"
)
func main() {
// Retry strategy for rate limits
var attemptRequest func() error
attemptRequest = func() error {
// Simulate API call
return &errors.APIError{
Provider: "openai",
StatusCode: 429,
Message: "Rate limit: 3 per second",
}
}
maxRetries := 3
for i := range maxRetries {
err := attemptRequest()
if apiErr, ok := err.(*errors.APIError); ok && apiErr.StatusCode == 429 {
fmt.Printf("Attempt %d: Rate limited, retrying...\n", i+1)
time.Sleep(time.Second) // Simple backoff
continue
}
if err != nil {
log.Fatal(err)
}
break
}
}
Output:
Example (ErrorWrapping) ¶
Example_errorWrapping shows error wrapping patterns.
package main
import (
"fmt"
"github.com/agentstation/starmap/pkg/errors"
)
func main() {
// Original error
originalErr := fmt.Errorf("connection refused")
// Wrap with IO error
ioErr := errors.WrapIO("connect", "api.openai.com", originalErr)
// Wrap with API error
_ = &errors.APIError{
Provider: "openai",
Endpoint: "https://api.openai.com/v1/models",
StatusCode: 0,
Message: "Failed to connect",
Err: ioErr,
}
// API error type is already known
fmt.Println("API error occurred")
}
Output: API error occurred
Example (HTTPStatusMapping) ¶
Example_hTTPStatusMapping maps HTTP codes to error types.
package main
import (
"fmt"
"net/http"
"github.com/agentstation/starmap/pkg/errors"
)
func main() {
// Map HTTP status to appropriate error
mapHTTPError := func(status int, provider string) error {
switch status {
case http.StatusNotFound:
return &errors.NotFoundError{
Resource: "endpoint",
ID: provider,
}
case http.StatusUnauthorized:
return &errors.AuthenticationError{
Provider: provider,
Message: "Invalid credentials",
}
case http.StatusTooManyRequests:
return &errors.APIError{
Provider: provider,
StatusCode: 429,
Message: "Rate limit exceeded",
}
default:
return &errors.APIError{
Provider: provider,
StatusCode: status,
Message: http.StatusText(status),
}
}
}
err := mapHTTPError(401, "openai")
if _, ok := err.(*errors.AuthenticationError); ok {
fmt.Println("Authentication required")
}
}
Output: Authentication required
Example (ProcessError) ¶
Example_processError shows subprocess error handling.
package main
import (
"fmt"
"github.com/agentstation/starmap/pkg/errors"
)
func main() {
// Create process error
err := &errors.ProcessError{
Operation: "git clone",
Command: "git clone https://github.com/repo.git",
Output: "fatal: repository not found",
ExitCode: 128,
}
// Handle process errors
fmt.Printf("Command failed with exit code %d\n", err.ExitCode)
if err.ExitCode == 128 {
fmt.Println("Git configuration error")
}
}
Output: Command failed with exit code 128 Git configuration error
Example (RateLimitError) ¶
Example_rateLimitError shows rate limit handling with retry.
package main
import (
"fmt"
"github.com/agentstation/starmap/pkg/errors"
)
func main() {
// Create API error for rate limiting
err := &errors.APIError{
Provider: "openai",
StatusCode: 429,
Message: "Rate limit exceeded. Try again in 30 seconds.",
}
// Handle rate limit
if err.StatusCode == 429 {
fmt.Printf("Rate limited: %s\n", err.Message)
}
}
Output: Rate limited: Rate limit exceeded. Try again in 30 seconds.
Example (ValidationError) ¶
Example_validationError shows input validation errors.
package main
import (
"fmt"
"github.com/agentstation/starmap/pkg/errors"
)
func main() {
// Validate input
apiKey := ""
if apiKey == "" {
err := &errors.ValidationError{
Field: "api_key",
Value: apiKey,
Message: "API key cannot be empty",
}
fmt.Println(err.Error())
}
}
Output: validation failed for field api_key: API key cannot be empty
Index ¶
- Variables
- func IsAPIKeyError(err error) bool
- func IsAlreadyExists(err error) bool
- func IsCanceled(err error) bool
- func IsConflict(err error) bool
- func IsNotFound(err error) bool
- func IsProviderUnavailable(err error) bool
- func IsRateLimited(err error) bool
- func IsTimeout(err error) bool
- func IsValidationError(err error) bool
- func WrapAPI(provider string, statusCode int, err error) error
- func WrapIO(operation, path string, err error) error
- func WrapParse(format, file string, err error) error
- func WrapResource(operation, resource, id string, err error) error
- func WrapValidation(field string, err error) error
- type APIError
- type AuthenticationError
- type ConfigError
- type ConflictError
- type DependencyError
- type IOError
- type LegacyCatalogLayoutError
- type NotFoundError
- type ParseError
- type ProcessError
- type PublicationError
- type ResourceError
- type SyncError
- type TimeoutError
- type ValidationError
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound indicates that a requested resource was not found. ErrNotFound = errors.New("not found") // ErrAlreadyExists indicates that a resource already exists. ErrAlreadyExists = errors.New("already exists") // ErrInvalidInput indicates that provided input was invalid. ErrInvalidInput = errors.New("invalid input") ErrAPIKeyRequired = errors.New("API key required") // ErrAPIKeyInvalid indicates that the provided API key is invalid. ErrAPIKeyInvalid = errors.New("API key invalid") ErrProviderUnavailable = errors.New("provider unavailable") ErrRateLimited = errors.New("rate limited") // ErrTimeout indicates that an operation timed out. ErrTimeout = errors.New("operation timed out") ErrCanceled = errors.New("operation canceled") // ErrNotImplemented indicates that a feature is not yet implemented. ErrNotImplemented = errors.New("not implemented") // ErrReadOnly indicates an attempt to modify a read-only resource. ErrReadOnly = errors.New("read only") // ErrConflict indicates an optimistic concurrency or immutable identity conflict. ErrConflict = errors.New("conflict") )
Common sentinel errors for the starmap system.
Functions ¶
func IsAPIKeyError ¶
IsAPIKeyError reports whether an error concerns an API key.
func IsAlreadyExists ¶
IsAlreadyExists checks if an error is an already exists error.
func IsCanceled ¶
IsCanceled checks if an error is a cancellation error.
func IsConflict ¶ added in v0.1.0
IsConflict checks if an error is an optimistic concurrency or immutable identity conflict.
func IsNotFound ¶
IsNotFound checks if an error is a not found error.
func IsProviderUnavailable ¶
IsProviderUnavailable checks if an error indicates provider unavailability.
func IsRateLimited ¶
IsRateLimited checks if an error is a rate limit error.
func IsValidationError ¶
IsValidationError checks if an error is a validation error.
func WrapResource ¶
WrapResource wraps an error as a ResourceError.
func WrapValidation ¶
WrapValidation wraps an error as a ValidationError.
Types ¶
type APIError ¶
type APIError struct {
Provider string // Provider ID as string
StatusCode int
Message string
Endpoint string
Err error
}
APIError represents an error from a provider API.
func NewAPIError ¶
NewAPIError creates a new APIError.
type AuthenticationError ¶
type AuthenticationError struct {
Provider string
Method string // "api_key", "oauth", "basic", etc.
Message string
Err error
}
AuthenticationError represents an authentication/authorization error.
func NewAuthenticationError ¶
func NewAuthenticationError(provider, method, message string, err error) *AuthenticationError
NewAuthenticationError creates a new AuthenticationError.
func (*AuthenticationError) Error ¶
func (e *AuthenticationError) Error() string
Error implements the error interface.
func (*AuthenticationError) Is ¶
func (e *AuthenticationError) Is(target error) bool
Is implements errors.Is support.
func (*AuthenticationError) Unwrap ¶
func (e *AuthenticationError) Unwrap() error
Unwrap implements errors.Unwrap.
type ConfigError ¶
ConfigError represents a configuration error.
func NewConfigError ¶
func NewConfigError(component, message string, err error) *ConfigError
NewConfigError creates a new ConfigError.
func (*ConfigError) Error ¶
func (e *ConfigError) Error() string
Error implements the error interface.
type ConflictError ¶ added in v0.1.0
ConflictError reports a version mismatch or immutable identity reuse with different content.
func (*ConflictError) Error ¶ added in v0.1.0
func (e *ConflictError) Error() string
Error implements the error interface.
func (*ConflictError) Is ¶ added in v0.1.0
func (e *ConflictError) Is(target error) bool
Is implements errors.Is support.
type DependencyError ¶
type DependencyError struct {
// Source identifies the catalog source that requires the dependency.
Source string
Dependency string
Message string
}
DependencyError reports a missing external dependency.
func (*DependencyError) Error ¶
func (e *DependencyError) Error() string
Error implements the error interface.
type IOError ¶
type IOError struct {
Operation string // "read", "write", "create", "delete", "open", "close"
Path string
Message string
Err error
}
IOError represents an error during I/O operations.
func NewIOError ¶
NewIOError creates a new IOError.
type LegacyCatalogLayoutError ¶ added in v0.2.0
LegacyCatalogLayoutError reports that a path selected for the human YAML workspace still contains the pre-plan immutable generation-store layout. Callers can use the structured paths and entries to present or execute an explicit transactional migration.
func (*LegacyCatalogLayoutError) Error ¶ added in v0.2.0
func (e *LegacyCatalogLayoutError) Error() string
Error implements the error interface.
type NotFoundError ¶
NotFoundError represents an error when a resource is not found.
func NewNotFoundError ¶
func NewNotFoundError(resource, id string) *NotFoundError
NewNotFoundError creates a new NotFoundError.
func (*NotFoundError) Error ¶
func (e *NotFoundError) Error() string
Error implements the error interface.
func (*NotFoundError) Is ¶
func (e *NotFoundError) Is(target error) bool
Is implements errors.Is support.
type ParseError ¶
type ParseError struct {
Format string // "json", "yaml", "toml", etc.
File string
Line int
Column int
Message string
Err error
}
ParseError represents an error when parsing data formats.
func NewParseError ¶
func NewParseError(format, file string, message string, err error) *ParseError
NewParseError creates a new ParseError.
func (*ParseError) Error ¶
func (e *ParseError) Error() string
Error implements the error interface.
type ProcessError ¶
type ProcessError struct {
Operation string
Command string
Output string // Stdout/stderr output from the process
ExitCode int // Exit code if available
Err error // Underlying error
}
ProcessError represents an error from an external process or command.
func NewProcessError ¶
func NewProcessError(operation, command, output string, err error) *ProcessError
NewProcessError creates a new ProcessError.
func (*ProcessError) Error ¶
func (e *ProcessError) Error() string
Error implements the error interface.
func (*ProcessError) Unwrap ¶
func (e *ProcessError) Unwrap() error
Unwrap implements errors.Unwrap.
type PublicationError ¶ added in v0.17.0
PublicationError reports visible publication whose durability remains unconfirmed. Resource and ID identify the published record. Callers must not infer rollback. Retry the same content and identity after resolving the underlying failure.
func (*PublicationError) Error ¶ added in v0.17.0
func (e *PublicationError) Error() string
Error identifies the publication and its durability failure.
func (*PublicationError) Unwrap ¶ added in v0.17.0
func (e *PublicationError) Unwrap() error
Unwrap preserves the underlying filesystem error.
type ResourceError ¶
type ResourceError struct {
Operation string // "create", "update", "delete", "fetch"
Resource string // "catalog", "provider", "model", "author"
ID string
Message string
Err error
}
ResourceError represents an error during resource operations.
func NewResourceError ¶
func NewResourceError(operation, resource, id string, err error) *ResourceError
NewResourceError creates a new ResourceError.
func (*ResourceError) Error ¶
func (e *ResourceError) Error() string
Error implements the error interface.
func (*ResourceError) Unwrap ¶
func (e *ResourceError) Unwrap() error
Unwrap implements errors.Unwrap.
type SyncError ¶
SyncError represents an error during sync operations.
func NewSyncError ¶
NewSyncError creates a new SyncError.
type TimeoutError ¶
TimeoutError represents an operation timeout.
func NewTimeoutError ¶
func NewTimeoutError(operation, duration, message string) *TimeoutError
NewTimeoutError creates a new TimeoutError.
func (*TimeoutError) Error ¶
func (e *TimeoutError) Error() string
Error implements the error interface.
func (*TimeoutError) Is ¶
func (e *TimeoutError) Is(target error) bool
Is implements errors.Is support.
type ValidationError ¶
ValidationError represents a validation failure.
func NewValidationError ¶
func NewValidationError(field string, value any, message string) *ValidationError
NewValidationError creates a new ValidationError.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
Error implements the error interface.
func (*ValidationError) Is ¶
func (e *ValidationError) Is(target error) bool
Is implements errors.Is support.