Unexport package-internal symbols with no external callers: - errors: IsConflict, IsCycle, IsNotFound - util: IsUniqueConstraintError (removed duplicate), IsForeignKeyConstraintError, IsBusyError - external_deps: CheckExternalDep, CheckExternalDeps, GetUnsatisfiedExternalDeps, ExternalDepStatus - collision: CollisionResult, CollisionDetail, RenameDetail - ids: GetAdaptiveIDLength, IsHierarchicalID, ValidateIssueIDPrefix, GenerateBatchIssueIDs, EnsureIDs - freshness: FreshnessChecker, NewFreshnessChecker - migration_invariants: MigrationInvariant, CleanOrphanedRefs - migrations: MigrationInfo - schema_probe: SchemaProbeResult, ErrSchemaIncompatible - ready: ExcludeIDPatternsConfigKey, DefaultExcludeIDPatterns - config: CustomStatusConfigKey, CustomTypeConfigKey Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
62 lines
1.7 KiB
Go
62 lines
1.7 KiB
Go
package sqlite
|
|
|
|
import (
|
|
"database/sql"
|
|
"errors"
|
|
"fmt"
|
|
)
|
|
|
|
// Sentinel errors for common database conditions
|
|
var (
|
|
// ErrNotFound indicates the requested resource was not found in the database
|
|
ErrNotFound = errors.New("not found")
|
|
|
|
// ErrInvalidID indicates an ID format or validation error
|
|
ErrInvalidID = errors.New("invalid ID")
|
|
|
|
// ErrConflict indicates a unique constraint violation or conflicting state
|
|
ErrConflict = errors.New("conflict")
|
|
|
|
// ErrCycle indicates a dependency cycle would be created
|
|
ErrCycle = errors.New("dependency cycle detected")
|
|
)
|
|
|
|
// wrapDBError wraps a database error with operation context
|
|
// It converts sql.ErrNoRows to ErrNotFound for consistent error handling
|
|
func wrapDBError(op string, err error) error {
|
|
if err == nil {
|
|
return nil
|
|
}
|
|
if errors.Is(err, sql.ErrNoRows) {
|
|
return fmt.Errorf("%s: %w", op, ErrNotFound)
|
|
}
|
|
return fmt.Errorf("%s: %w", op, err)
|
|
}
|
|
|
|
// wrapDBErrorf wraps a database error with formatted operation context
|
|
// It converts sql.ErrNoRows to ErrNotFound for consistent error handling
|
|
func wrapDBErrorf(err error, format string, args ...interface{}) error {
|
|
if err == nil {
|
|
return nil
|
|
}
|
|
op := fmt.Sprintf(format, args...)
|
|
if errors.Is(err, sql.ErrNoRows) {
|
|
return fmt.Errorf("%s: %w", op, ErrNotFound)
|
|
}
|
|
return fmt.Errorf("%s: %w", op, err)
|
|
}
|
|
|
|
// isNotFound checks if an error is or wraps ErrNotFound
|
|
func isNotFound(err error) bool {
|
|
return errors.Is(err, ErrNotFound)
|
|
}
|
|
|
|
// isConflict checks if an error is or wraps ErrConflict
|
|
func isConflict(err error) bool {
|
|
return errors.Is(err, ErrConflict)
|
|
}
|
|
|
|
// isCycle checks if an error is or wraps ErrCycle
|
|
func isCycle(err error) bool {
|
|
return errors.Is(err, ErrCycle)
|
|
}
|