Use zap.Error for logging errors #1559

Merged
fyrchik merged 1 commit from a-savchuk/frostfs-node:patch-zap-error into master 2024-12-16 08:30:28 +00:00
Member

Close #1502

Use zap.Error instead of zap.String for logging errors: change all expressions like zap.String("error", err.Error()) or zap.String("err", err.Error()) to zap.Error(err). Leave similar expressions with other messages unchanged, for example, zap.String("last_error", lastErr.Error()) or zap.String("reason", ctx.Err().Error()).

This change was made by applying the following patch:

@@
var err expression
@@
-zap.String("error", err.Error())
+zap.Error(err)

@@
var err expression
@@
-zap.String("err", err.Error())
+zap.Error(err)
Close #1502 Use `zap.Error` instead of `zap.String` for logging errors: change all expressions like `zap.String("error", err.Error())` or `zap.String("err", err.Error())` to `zap.Error(err)`. Leave similar expressions with other messages unchanged, for example, `zap.String("last_error", lastErr.Error())` or `zap.String("reason", ctx.Err().Error())`. This change was made by applying the following patch: ```diff @@ var err expression @@ -zap.String("error", err.Error()) +zap.Error(err) @@ var err expression @@ -zap.String("err", err.Error()) +zap.Error(err) ```
a-savchuk added 1 commit 2024-12-13 09:07:09 +00:00
[#1502] Use zap.Error for logging errors
All checks were successful
Vulncheck / Vulncheck (pull_request) Successful in 2m51s
Pre-commit hooks / Pre-commit (pull_request) Successful in 3m13s
Tests and linters / gopls check (pull_request) Successful in 3m39s
Tests and linters / Run gofumpt (pull_request) Successful in 3m58s
DCO action / DCO (pull_request) Successful in 4m18s
Build / Build Components (pull_request) Successful in 5m13s
Tests and linters / Tests (pull_request) Successful in 5m30s
Tests and linters / Staticcheck (pull_request) Successful in 5m30s
Tests and linters / Lint (pull_request) Successful in 6m17s
Tests and linters / Tests with -race (pull_request) Successful in 6m36s
74d9bb0e05
Use `zap.Error` instead of `zap.String` for logging errors: change all expressions like
`zap.String("error", err.Error())` or `zap.String("err", err.Error())` to `zap.Error(err)`.
Leave similar expressions with other messages unchanged, for example,
`zap.String("last_error", lastErr.Error())` or `zap.String("reason", ctx.Err().Error())`.

This change was made by applying the following patch:
```diff
@@
var err identifier
@@
-zap.String("error", err.Error())
+zap.Error(err)

@@
var err identifier
@@
-zap.String("error", err.String())
+zap.Error(err)

@@
var err identifier
@@
-zap.Stringer("error", err)
+zap.Error(err)

@@
var errExpr expression
@@
-zap.String("error", errExpr.Error())
+zap.Error(errExpr)

@@
var errExpr expression
@@
-zap.String("error", errExpr.String())
+zap.Error(errExpr)

@@
var errExpr expression
@@
-zap.Stringer("error", errExpr)
+zap.Error(errExpr)

@@
var err identifier
@@
-zap.String("err", err.Error())
+zap.Error(err)

@@
var err identifier
@@
-zap.String("err", err.String())
+zap.Error(err)

@@
var err identifier
@@
-zap.Stringer("err", err)
+zap.Error(err)

@@
var errExpr expression
@@
-zap.String("err", errExpr.Error())
+zap.Error(errExpr)

@@
var errExpr expression
@@
-zap.String("err", errExpr.String())
+zap.Error(errExpr)

@@
var errExpr expression
@@
-zap.Stringer("err", errExpr)
+zap.Error(errExpr)
```

Signed-off-by: Aleksey Savchuk <a.savchuk@yadro.com>
a-savchuk requested review from storage-core-committers 2024-12-13 09:07:10 +00:00
a-savchuk requested review from storage-core-developers 2024-12-13 09:07:10 +00:00
acid-ant approved these changes 2024-12-13 09:23:04 +00:00
aarifullin approved these changes 2024-12-16 07:30:54 +00:00
aarifullin left a comment
Member

Very nice

Very nice
Owner

Why the cases with .String? I do not see lines like this in the PR and these values do not implement error in general.

Why the cases with `.String`? I do not see lines like this in the PR and these values do not implement `error` in general.
a-savchuk force-pushed patch-zap-error from 74d9bb0e05 to b2749b1ed9 2024-12-16 07:50:40 +00:00 Compare
a-savchuk force-pushed patch-zap-error from b2749b1ed9 to 2e7f98b09b 2024-12-16 07:51:46 +00:00 Compare
Author
Member

Why the cases with .String? I do not see lines like this in the PR and these values do not implement error in general.

Fixed

> Why the cases with `.String`? I do not see lines like this in the PR and these values do not implement `error` in general. Fixed
Owner

Also, an identifier is an expression, so no need to have a separate case for it.

Also, an identifier is an expression, so no need to have a separate case for it.
Author
Member

Also, an identifier is an expression, so no need to have a separate case for it.

Fixed

> Also, an identifier is an expression, so no need to have a separate case for it. Fixed
a-savchuk force-pushed patch-zap-error from 2e7f98b09b to f0c43c8d80 2024-12-16 08:15:49 +00:00 Compare
fyrchik approved these changes 2024-12-16 08:30:23 +00:00
fyrchik merged commit f0c43c8d80 into master 2024-12-16 08:30:28 +00:00
a-savchuk deleted branch patch-zap-error 2024-12-16 08:46:21 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
4 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: TrueCloudLab/frostfs-node#1559
No description provided.