Skip to content

Commit e08d56c

Browse files
committed
fix(inline handlers): panic on invalid argument
1 parent b68009c commit e08d56c

6 files changed

+51
-0
lines changed

handler_inline.go

+7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ func NewInlineHandler(
1111
enabledFunc func(ctx context.Context, groups []string, attrs []slog.Attr, level slog.Level) bool,
1212
handleFunc func(ctx context.Context, groups []string, attrs []slog.Attr, record slog.Record) error,
1313
) slog.Handler {
14+
if enabledFunc == nil {
15+
panic("slog-multi: enabledFunc is required")
16+
}
17+
if handleFunc == nil {
18+
panic("slog-multi: handleFunc is required")
19+
}
20+
1421
return &InlineHandler{
1522
groups: []string{},
1623
attrs: []slog.Attr{},

middleware_inline.go

+16
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,22 @@ func NewInlineMiddleware(
1414
withGroupFunc func(name string, next func(string) slog.Handler) slog.Handler,
1515
) Middleware {
1616
return func(next slog.Handler) slog.Handler {
17+
if next == nil {
18+
panic("slog-multi: next is required")
19+
}
20+
if enabledFunc == nil {
21+
panic("slog-multi: enabledFunc is required")
22+
}
23+
if handleFunc == nil {
24+
panic("slog-multi: handleFunc is required")
25+
}
26+
if withAttrsFunc == nil {
27+
panic("slog-multi: withAttrsFunc is required")
28+
}
29+
if withGroupFunc == nil {
30+
panic("slog-multi: withGroupFunc is required")
31+
}
32+
1733
return &InlineMiddleware{
1834
next: next,
1935
enabledFunc: enabledFunc,

middleware_inline_enabled.go

+7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ import (
99
// NewEnabledInlineMiddleware is shortcut to a middleware that implements only the `Enable` method.
1010
func NewEnabledInlineMiddleware(enabledFunc func(ctx context.Context, level slog.Level, next func(context.Context, slog.Level) bool) bool) Middleware {
1111
return func(next slog.Handler) slog.Handler {
12+
if enabledFunc == nil {
13+
panic("slog-multi: enabledFunc is required")
14+
}
15+
if next == nil {
16+
panic("slog-multi: next is required")
17+
}
18+
1219
return &EnabledInlineMiddleware{
1320
next: next,
1421
enabledFunc: enabledFunc,

middleware_inline_handle.go

+7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ import (
99
// NewHandleInlineMiddleware is a shortcut to a middleware that implements only the `Handle` method.
1010
func NewHandleInlineMiddleware(handleFunc func(ctx context.Context, record slog.Record, next func(context.Context, slog.Record) error) error) Middleware {
1111
return func(next slog.Handler) slog.Handler {
12+
if next == nil {
13+
panic("slog-multi: next is required")
14+
}
15+
if handleFunc == nil {
16+
panic("slog-multi: handleFunc is required")
17+
}
18+
1219
return &HandleInlineMiddleware{
1320
next: next,
1421
handleFunc: handleFunc,

middleware_inline_with_attrs.go

+7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ import (
99
// NewWithAttrsInlineMiddleware is a shortcut to a middleware that implements only the `WithAttrs` method.
1010
func NewWithAttrsInlineMiddleware(withAttrsFunc func(attrs []slog.Attr, next func([]slog.Attr) slog.Handler) slog.Handler) Middleware {
1111
return func(next slog.Handler) slog.Handler {
12+
if withAttrsFunc == nil {
13+
panic("slog-multi: withAttrsFunc is required")
14+
}
15+
if next == nil {
16+
panic("slog-multi: next is required")
17+
}
18+
1219
return &WithAttrsInlineMiddleware{
1320
next: next,
1421
withAttrsFunc: withAttrsFunc,

middleware_inline_with_group.go

+7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ import (
99
// NewWithGroupInlineMiddleware is a shortcut to a middleware that implements only the `WithAttrs` method.
1010
func NewWithGroupInlineMiddleware(withGroupFunc func(name string, next func(string) slog.Handler) slog.Handler) Middleware {
1111
return func(next slog.Handler) slog.Handler {
12+
if next == nil {
13+
panic("slog-multi: next is required")
14+
}
15+
if withGroupFunc == nil {
16+
panic("slog-multi: withGroupFunc is required")
17+
}
18+
1219
return &WithGroupInlineMiddleware{
1320
next: next,
1421
withGroupFunc: withGroupFunc,

0 commit comments

Comments
 (0)