* Implement panic recovery and graceful error handling for services - Added panic recovery to CLI entry point (`Main`) with logging and stack traces. - Refactored `MustServiceFor`, `Config()`, and `Display()` to return errors instead of panicking. - Updated `CLAUDE.md` to reflect the service retrieval API change. - Made `signalService.OnShutdown` idempotent to prevent panics during redundant shutdowns. - Updated all relevant tests and call sites. * Implement panic recovery and graceful error handling for services (with formatting fix) - Added panic recovery to CLI entry point (`Main`) with logging and stack traces. - Refactored `MustServiceFor`, `Config()`, and `Display()` to return errors instead of panicking. - Updated `CLAUDE.md` to reflect the service retrieval API change. - Made `signalService.OnShutdown` idempotent to prevent panics during redundant shutdowns. - Fixed formatting issues in `pkg/cli/runtime.go`. - Updated all relevant tests and call sites. * Implement panic recovery and graceful error handling for services (with CI fixes) - Added panic recovery to CLI entry point (`Main`) with logging and stack traces. - Refactored `MustServiceFor`, `Config()`, and `Display()` to return errors instead of panicking. - Updated `CLAUDE.md` to reflect the service retrieval API change. - Made `signalService.OnShutdown` idempotent to prevent panics during redundant shutdowns. - Fixed `auto-merge.yml` workflow by inlining logic and adding the `--repo` flag to the `gh` command. - Applied formatting to `pkg/io/local/client.go`. - Updated all relevant tests and call sites. * Implement panic recovery and graceful error handling (final fix) - Added panic recovery to CLI entry point (`Main`) with logging and stack traces. - Refactored `MustServiceFor`, `Config()`, and `Display()` to return errors instead of panicking. - Updated `CLAUDE.md` to reflect the service retrieval API change. - Made `signalService.OnShutdown` idempotent to prevent panics during redundant shutdowns. - Reverted unrelated changes to `auto-merge.yml`. - Fixed formatting issues in `pkg/io/local/client.go`. - Verified all call sites and tests. * fix: address code review comments - Add deprecation notices to MustServiceFor functions in core and framework packages to clarify they no longer panic per Go naming conventions - Update process/types.go example to show proper error handling instead of discarding errors with blank identifier - Add comprehensive test coverage for panic recovery mechanism in app.go Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude <developers@lethean.io> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
75 lines
2.2 KiB
Go
75 lines
2.2 KiB
Go
// Package framework provides the Core DI/service framework.
|
|
// Import this package for cleaner access to the framework types.
|
|
//
|
|
// Usage:
|
|
//
|
|
// import "github.com/host-uk/core/pkg/framework"
|
|
//
|
|
// app, _ := framework.New(
|
|
// framework.WithServiceLock(),
|
|
// )
|
|
package framework
|
|
|
|
import (
|
|
"github.com/host-uk/core/pkg/framework/core"
|
|
)
|
|
|
|
// Re-export core types for cleaner imports
|
|
type (
|
|
Core = core.Core
|
|
Option = core.Option
|
|
Message = core.Message
|
|
Query = core.Query
|
|
Task = core.Task
|
|
QueryHandler = core.QueryHandler
|
|
TaskHandler = core.TaskHandler
|
|
Startable = core.Startable
|
|
Stoppable = core.Stoppable
|
|
Config = core.Config
|
|
Display = core.Display
|
|
WindowOption = core.WindowOption
|
|
Features = core.Features
|
|
Contract = core.Contract
|
|
Error = core.Error
|
|
ServiceRuntime[T any] = core.ServiceRuntime[T]
|
|
Runtime = core.Runtime
|
|
ServiceFactory = core.ServiceFactory
|
|
)
|
|
|
|
// Re-export core functions
|
|
var (
|
|
New = core.New
|
|
WithService = core.WithService
|
|
WithName = core.WithName
|
|
WithApp = core.WithApp
|
|
WithAssets = core.WithAssets
|
|
WithServiceLock = core.WithServiceLock
|
|
App = core.App
|
|
E = core.E
|
|
NewRuntime = core.NewRuntime
|
|
NewWithFactories = core.NewWithFactories
|
|
)
|
|
|
|
// NewServiceRuntime creates a new ServiceRuntime for a service.
|
|
func NewServiceRuntime[T any](c *Core, opts T) *ServiceRuntime[T] {
|
|
return core.NewServiceRuntime(c, opts)
|
|
}
|
|
|
|
// ServiceFor retrieves a typed service from the core container by name.
|
|
func ServiceFor[T any](c *Core, name string) (T, error) {
|
|
return core.ServiceFor[T](c, name)
|
|
}
|
|
|
|
// MustServiceFor retrieves a typed service or returns an error if not found.
|
|
//
|
|
// Deprecated: use ServiceFor instead. This function does not panic on failure
|
|
// and is retained only for backward compatibility.
|
|
func MustServiceFor[T any](c *Core, name string) (T, error) {
|
|
return core.MustServiceFor[T](c, name)
|
|
}
|
|
|
|
// Action types
|
|
type (
|
|
ActionServiceStartup = core.ActionServiceStartup
|
|
ActionServiceShutdown = core.ActionServiceShutdown
|
|
)
|