From 5cd1fc51867f695f4949eec7389cc92866878c2f Mon Sep 17 00:00:00 2001 From: Gabriel Cataldo Date: Wed, 7 Feb 2024 20:16:41 -0300 Subject: [PATCH] Bug fix for detail error on detail error, if one of the parameters is the detail error itself, we only get the same message. --- README.md | 2 +- errors/errors.go | 7 +++++++ errors/errors_test.go | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e38672d..ed0b280 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Go Errors Detail -[![Project status](https://img.shields.io/badge/version-v1.1.5-vividgreen.svg)](https://github.com/GabrielHCataldo/go-errors/releases/tag/v1.1.5) +[![Project status](https://img.shields.io/badge/version-v1.1.6-vividgreen.svg)](https://github.com/GabrielHCataldo/go-errors/releases/tag/v1.1.6) [![Go Report Card](https://goreportcard.com/badge/github.com/GabrielHCataldo/go-errors)](https://goreportcard.com/report/github.com/GabrielHCataldo/go-errors) [![Coverage Status](https://coveralls.io/repos/GabrielHCataldo/go-errors/badge.svg?branch=main&service=github)](https://coveralls.io/github/GabrielHCataldo/go-errors?branch=main) [![Open Source Helpers](https://www.codetriage.com/gabrielhcataldo/go-errors/badges/users.svg)](https://www.codetriage.com/gabrielhcataldo/go-errors) diff --git a/errors/errors.go b/errors/errors.go index 1eb0cac..b091289 100644 --- a/errors/errors.go +++ b/errors/errors.go @@ -178,6 +178,13 @@ func Details(err error) *ErrorDetail { } func printMessage(v ...any) string { + for i, iv := range v { + ivError, ok := iv.(error) + if helper.IsError(iv) && ok { + errDetail := Details(ivError) + v[i] = errDetail.message + } + } msg := helper.Sprintln(v...) msg = strings.ReplaceAll(msg, "[STACK]", "") msg = strings.ReplaceAll(msg, "[CAUSE]", "") diff --git a/errors/errors_test.go b/errors/errors_test.go index d40270c..c4a125a 100644 --- a/errors/errors_test.go +++ b/errors/errors_test.go @@ -8,6 +8,7 @@ import ( func TestNew(t *testing.T) { logger.Info("err:", New("test error detail")) + logger.Info("err:", New("test error detail", New("sub error message"))) logger.Info("err:", New("")) }