Skip to content
This repository has been archived by the owner on Mar 15, 2024. It is now read-only.

Commit

Permalink
fix #118 nil caller encoder causes segfault, changed to CallerDisable…
Browse files Browse the repository at this point in the history
…d option

add test for this case
  • Loading branch information
archaron committed Mar 25, 2022
1 parent 585a4d1 commit f28f841
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions helium_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"testing"

"bou.ke/monkey"
"github.com/spf13/viper"
"github.com/stretchr/testify/require"
"go.uber.org/dig"
"go.uber.org/zap"
Expand Down Expand Up @@ -100,6 +101,26 @@ func TestHelium(t *testing.T) {
require.NoError(t, h.Run())
})

t.Run("start new helium default app with json logger and no_caller should not cause exceptions", func(t *testing.T) {
require.NotPanics(t, func() {
h, err := New(&Settings{
Defaults: func(v *viper.Viper) {
v.SetDefault("logger.format", "json")
v.SetDefault("logger.no_caller", true)
},
},
DefaultApp,
grace.Module,
settings.Module,
logger.Module,
)

require.NotNil(t, h)
require.NoError(t, err)
require.NoError(t, h.Run())
})
})

t.Run("create new helium should fail on new", func(t *testing.T) {
h, err := New(&Settings{}, module.Module{
{Constructor: func() error { return nil }},
Expand Down
2 changes: 1 addition & 1 deletion logger/zap.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func NewLogger(lcfg *Config, app *settings.Core) (*zap.Logger, error) {
}

if lcfg.NoCaller {
cfg.EncoderConfig.EncodeCaller = nil
cfg.DisableCaller = true
}

if lcfg.FullCaller {
Expand Down

0 comments on commit f28f841

Please sign in to comment.