Skip to content

Fix error handling, SQLite safety, and API naming#4

Merged
simonovic86 merged 1 commit intomainfrom
claude/youthful-gauss
Mar 10, 2026
Merged

Fix error handling, SQLite safety, and API naming#4
simonovic86 merged 1 commit intomainfrom
claude/youthful-gauss

Conversation

@simonovic86
Copy link
Owner

Changes

Error Handling Improvements

  • registry.go: Changed Register() to return error instead of panicking; added MustRegister() for panic behavior and new Overwrite() for testing
  • typed.go: Typed() now returns (Spec, error) instead of silently failing; added MustTyped() for panic behavior
  • storage: Added proper error handling for JSON marshaling in both PostgreSQL and SQLite implementations
  • func.go: Updated to use MustRegister() for registration

SQLite Safety Fixes

  • storage/sqlite.go: Set MaxOpenConns(1) to avoid SQLITE_BUSY errors
  • Added PRAGMA busy_timeout=5000 to wait for locks instead of failing immediately
  • Fixed variable shadowing issue in Create() method (renamed err to execErr)

API Naming & Deprecation

  • options.go: Renamed WithDefaultRepeatInterval() to WithDefaultPeriod() for consistency; kept old name as deprecated alias
  • spec.go: Added builder methods: WithPeriod(), WithCron(), WithSequence(), WithDeadlineAt()
  • executor.go: Updated Register() call to use MustRegister()
  • examples: Updated to use MustTyped() instead of Typed()

Test Coverage

  • Added registry_test.go: Tests for Register(), MustRegister(), Overwrite()
  • Added spec_test.go: Tests for all new builder methods and chaining
  • Added typed_test.go: Tests for Typed(), MustTyped(), and recovery error handling

Fix silent error handling across storage layers and typed commands:
- SQLite Create/Update now check json.Marshal errors instead of discarding
- PostgreSQL postgresTx Create/Update same fix
- TypedCommand.Recover() returns unmarshal error instead of silently skipping

Improve SQLite connection safety:
- Add SetMaxOpenConns(1) to prevent SQLITE_BUSY errors
- Add PRAGMA busy_timeout=5000 for lock wait tolerance

Fix API naming to follow Go conventions:
- Registry.Register() now returns error (was panic)
- Registry.MustRegister() now panics on error (Go Must* convention)
- Add Registry.Overwrite() for silent replacement (old MustRegister behavior)
- Typed() now returns (Spec, error); add MustTyped() for panic variant
- Add WithDefaultPeriod() option, deprecate WithDefaultRepeatInterval()
- Add Spec builders: WithPeriod, WithCron, WithSequence, WithDeadlineAt

BREAKING CHANGES:
- Typed() signature changed from Spec to (Spec, error)
- Registry.Register() returns error instead of panicking
- Registry.MustRegister() now panics on duplicate (was silent overwrite)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@simonovic86 simonovic86 merged commit 72d49e3 into main Mar 10, 2026
3 checks passed
@simonovic86 simonovic86 deleted the claude/youthful-gauss branch March 10, 2026 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant