Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- More complete example test for `nilerror` package. [PR #27](https://github.com/riverqueue/rivercontrib/pull/27).

### Fixed

- Fix GitHub import path for `nilerror` package. [PR #29](https://github.com/riverqueue/rivercontrib/pull/29).
- Fix compliance of `nilerror.Hook` to `rivertype.HookWorkEnd` interface. [PR #30](https://github.com/riverqueue/rivercontrib/pull/30).

## [0.5.0] - 2025-05-02

### Added
Expand Down
3 changes: 2 additions & 1 deletion datadogriver/example_global_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package datadogriver_test

import (
"log/slog"
"os"

ddotel "github.com/DataDog/dd-trace-go/v2/ddtrace/opentelemetry"
"go.opentelemetry.io/otel"
Expand All @@ -19,7 +20,7 @@ func Example_globalProvider() {
otel.SetTracerProvider(provider)

_, err := river.NewClient(riverpgxv5.New(nil), &river.Config{
Logger: slog.New(&slogutil.SlogMessageOnlyHandler{Level: slog.LevelWarn}),
Logger: slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelWarn, ReplaceAttr: slogutil.NoLevelTime})),
Middleware: []rivertype.Middleware{
// Install the OpenTelemetry middleware to run for all jobs inserted
// or worked by this River client. The global provider is used.
Expand Down
3 changes: 2 additions & 1 deletion datadogriver/example_injected_provider_test.go
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably upgrade deps for datadog too, they've shipped a lot in the Go client since we released this package.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, good call.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package datadogriver_test

import (
"log/slog"
"os"

ddotel "github.com/DataDog/dd-trace-go/v2/ddtrace/opentelemetry"

Expand All @@ -17,7 +18,7 @@ func Example_injectedProvider() {
defer func() { _ = provider.Shutdown() }()

_, err := river.NewClient(riverpgxv5.New(nil), &river.Config{
Logger: slog.New(&slogutil.SlogMessageOnlyHandler{Level: slog.LevelWarn}),
Logger: slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelWarn, ReplaceAttr: slogutil.NoLevelTime})),
Middleware: []rivertype.Middleware{
// Install the OpenTelemetry middleware to run for all jobs inserted
// or worked by this River client. Inject a specific DataDog provider.
Expand Down
5 changes: 3 additions & 2 deletions nilerror/example_hook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package nilerror_test
import (
"context"
"log/slog"
"os"

"github.com/jackc/pgx/v5/pgxpool"

Expand Down Expand Up @@ -56,7 +57,7 @@ func ExampleHook() {
// Alternatively, return an error and fail jobs instead.
// nilerror.NewHook(nil),
},
Logger: slog.New(&slogutil.SlogMessageOnlyHandler{Level: slog.LevelWarn}),
Logger: slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelWarn, ReplaceAttr: slogutil.NoLevelTime})),
Queues: map[string]river.QueueConfig{
river.QueueDefault: {MaxWorkers: 100},
},
Expand Down Expand Up @@ -88,5 +89,5 @@ func ExampleHook() {
}

// Output:
// nilerror.Hook: Got non-nil error containing nil internal value (see: https://go.dev/doc/faq#nil_error); probably a bug: (*nilerror_test.CustomError)(<nil>)
// msg="nilerror.Hook: Got non-nil error containing nil internal value (see: https://go.dev/doc/faq#nil_error); probably a bug: (*nilerror_test.CustomError)(<nil>)"
}
8 changes: 4 additions & 4 deletions nilerror/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ go 1.24.2
require (
github.com/jackc/pgx/v5 v5.7.4
github.com/riverqueue/river v0.21.0
github.com/riverqueue/river/riverdriver/riverpgxv5 v0.21.0
github.com/riverqueue/river/rivershared v0.21.0
github.com/riverqueue/river/rivertype v0.21.0
github.com/riverqueue/river/riverdriver/riverpgxv5 v0.27.0
github.com/riverqueue/river/rivershared v0.27.0
github.com/riverqueue/river/rivertype v0.27.0
github.com/stretchr/testify v1.10.0
)

Expand All @@ -17,7 +17,7 @@ require (
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/puddle/v2 v2.2.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/riverqueue/river/riverdriver v0.21.0 // indirect
github.com/riverqueue/river/riverdriver v0.27.0 // indirect
github.com/tidwall/gjson v1.18.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
Expand Down
6 changes: 5 additions & 1 deletion nilerror/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import (
"github.com/riverqueue/river/rivertype"
)

// Verify interface compliance.
var _ rivertype.HookWorkEnd = &Hook{}

// HookConfig is configuration for the nilerror hook.
type HookConfig struct {
// Suppress causes the hook to suppress detected nil struct values wrapped
Expand All @@ -37,6 +40,7 @@ type HookConfig struct {
type Hook struct {
baseservice.BaseService
rivertype.Hook

config *HookConfig
}

Expand All @@ -50,7 +54,7 @@ func NewHook(config *HookConfig) *Hook {
return &Hook{config: config}
}

func (h *Hook) WorkEnd(ctx context.Context, err error) error {
func (h *Hook) WorkEnd(ctx context.Context, _ *rivertype.JobRow, err error) error {
if err != nil {
errVal := reflect.ValueOf(err)
if errVal.IsNil() {
Expand Down
17 changes: 6 additions & 11 deletions nilerror/hook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ import (
"github.com/riverqueue/river/rivertype"
)

// Verify interface compliance.
var (
_ rivertype.HookWorkEnd = &Hook{}
)

type myCustomError struct{}

func (*myCustomError) Error() string {
Expand Down Expand Up @@ -51,7 +46,7 @@ func TestHook(t *testing.T) {

hook, _ := setup(t)

require.NoError(t, hook.WorkEnd(ctx, nil))
require.NoError(t, hook.WorkEnd(ctx, &rivertype.JobRow{}, nil))
})

t.Run("NonNilError", func(t *testing.T) {
Expand All @@ -60,7 +55,7 @@ func TestHook(t *testing.T) {
hook, _ := setup(t)

myCustomErr := &myCustomError{}
require.Equal(t, myCustomErr, hook.WorkEnd(ctx, myCustomErr))
require.Equal(t, myCustomErr, hook.WorkEnd(ctx, &rivertype.JobRow{}, myCustomErr))
})

t.Run("NilError", func(t *testing.T) {
Expand All @@ -69,7 +64,7 @@ func TestHook(t *testing.T) {
hook, _ := setup(t)

var myCustomErr *myCustomError
require.EqualError(t, hook.WorkEnd(ctx, myCustomErr),
require.EqualError(t, hook.WorkEnd(ctx, &rivertype.JobRow{}, myCustomErr),
"non-nil error containing nil internal value (see: https://go.dev/doc/faq#nil_error); probably a bug: (*nilerror.myCustomError)(<nil>)",
)
})
Expand All @@ -80,13 +75,13 @@ func TestHook(t *testing.T) {
hook, _ := setupConfig(t, &HookConfig{Suppress: true})

var logBuf bytes.Buffer
hook.Logger = slog.New(&slogutil.SlogMessageOnlyHandler{Level: slog.LevelWarn, Out: &logBuf})
hook.Logger = slog.New(slog.NewTextHandler(&logBuf, &slog.HandlerOptions{Level: slog.LevelWarn, ReplaceAttr: slogutil.NoLevelTime}))

var myCustomErr *myCustomError
require.NoError(t, hook.WorkEnd(ctx, myCustomErr))
require.NoError(t, hook.WorkEnd(ctx, &rivertype.JobRow{}, myCustomErr))

require.Equal(t,
"nilerror.Hook: Got non-nil error containing nil internal value (see: https://go.dev/doc/faq#nil_error); probably a bug: (*nilerror.myCustomError)(<nil>)\n",
`msg="nilerror.Hook: Got non-nil error containing nil internal value (see: https://go.dev/doc/faq#nil_error); probably a bug: (*nilerror.myCustomError)(<nil>)"`+"\n",
logBuf.String())
})
}
3 changes: 2 additions & 1 deletion otelriver/example_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package otelriver_test

import (
"log/slog"
"os"

"github.com/riverqueue/river"
"github.com/riverqueue/river/riverdriver/riverpgxv5"
Expand All @@ -12,7 +13,7 @@ import (

func ExampleMiddleware() {
_, err := river.NewClient(riverpgxv5.New(nil), &river.Config{
Logger: slog.New(&slogutil.SlogMessageOnlyHandler{Level: slog.LevelWarn}),
Logger: slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelWarn, ReplaceAttr: slogutil.NoLevelTime})),
Middleware: []rivertype.Middleware{
// Install the OpenTelemetry middleware to run for all jobs inserted
// or worked by this River client.
Expand Down
Loading