Skip to content

*: replace erroneous uses of Newf/Errorf by Wrap/Wrapf#68707

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
knz:20210811-errors
Aug 12, 2021
Merged

*: replace erroneous uses of Newf/Errorf by Wrap/Wrapf#68707
craig[bot] merged 1 commit intocockroachdb:masterfrom
knz:20210811-errors

Conversation

@knz
Copy link
Copy Markdown
Contributor

@knz knz commented Aug 11, 2021

This is an omnibus PR touching code by multiple teams. To be reviewed as follows:

  • @adityamaru for the trace dumper changes
  • @jeffswenson @cockroachdb/sqlproxy-prs for the sql proxy code
  • @jbowens @cockroachdb/storage for the pebble changes
  • @mberhault @cockroachdb/storage for the store encryption code
  • @miretskiy for the doctor changes
  • @nvanbenschoten @cockroachdb/kv for the KV changes
  • @otan @cockroachdb/sql-experience for the GEO changes
  • @postamar @cockroachdb/sql-schema for the SQL catalog, index GC and SQL liveness changes
  • @cockroachdb/server-prs for the changes to the "security" and "server" packages

See the description below for an explanation.


When constructing an error from another error, it is generally
erroneous to use Errorf("...%v", err): this deconstructs the
original error back to a simple string and loses all its details.

It also makes the original error opaque to redactability, to be
considered an unsafe string, even if the original error already
contained a mix of safe and unsafe strings.

The proper approach is to use errors.Wrap / errors.Wrapf.
This preserves any embedded details inside the error object and its
redactability attributes.

This change was obtained by running the following command and fixing
up the results (i.e. test code was ignored):

git grep -E '(errors|fmt)\.(Errorf|Newf).*%v.*[eE]rr'|grep -v _test.go

Release note: None

@knz knz requested review from a team as code owners August 11, 2021 12:28
@knz knz requested a review from a team August 11, 2021 12:28
@knz knz requested review from a team as code owners August 11, 2021 12:28
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@knz
Copy link
Copy Markdown
Contributor Author

knz commented Aug 11, 2021

Arguably we'd need a linter for this.
Since preserving details in errors is distinctly an observability objective, I would suggest @dhartunian perhaps you could add a linter task to the backlog of your team?

@otan
Copy link
Copy Markdown
Contributor

otan commented Aug 11, 2021

geo lgtm

Copy link
Copy Markdown
Contributor

@mberhault mberhault left a comment

Choose a reason for hiding this comment

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

Reviewed 18 of 22 files at r1, 4 of 4 files at r2, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @knz)


pkg/ccl/cmdccl/enc_utils/main.go, line 205 at r2 (raw file):

	cipher, err := aes.NewCipher(key.rawKey)
	if err != nil {
		return nil, errors.Wrapf("could not build AES cipher for file %s", absPath)

err is not being wrapped.


pkg/cli/doctor.go, line 389 at r2 (raw file):

				id = int(descpb.InvalidID)
			} else {
				return errors.Errorf(err, "failed to parse id %s", fields[3])

This is still the original Errorf but with Wrapf arguments.


pkg/kv/kvserver/store_split.go, line 338 at r2 (raw file):

		leftRepl.writeStats.splitRequestCounts(rightRepl.writeStats)
		if err := s.addReplicaInternalLocked(rightRepl); err != nil {
			return errors.Wrapf(err, "unable to add replica %v: %s", rightRepl)

The %s for the err is still in the argument list.

@knz knz force-pushed the 20210811-errors branch from 81e25ad to 800a4e2 Compare August 11, 2021 13:06
Copy link
Copy Markdown
Contributor Author

@knz knz left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @knz and @mberhault)


pkg/ccl/cmdccl/enc_utils/main.go, line 205 at r2 (raw file):

Previously, mberhault (marc) wrote…

err is not being wrapped.

Good catch. Fixed.


pkg/cli/doctor.go, line 389 at r2 (raw file):

Previously, mberhault (marc) wrote…

This is still the original Errorf but with Wrapf arguments.

Thanks fixed.

@knz knz force-pushed the 20210811-errors branch from 800a4e2 to 9c57b1b Compare August 11, 2021 13:07
Copy link
Copy Markdown
Contributor Author

@knz knz left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @mberhault)


pkg/kv/kvserver/store_split.go, line 338 at r2 (raw file):

Previously, mberhault (marc) wrote…

The %s for the err is still in the argument list.

Fixed

Copy link
Copy Markdown
Contributor

@mberhault mberhault left a comment

Choose a reason for hiding this comment

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

Reviewed 3 of 3 files at r3, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @mberhault)

Copy link
Copy Markdown
Contributor

@mberhault mberhault left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @knz)

@knz knz force-pushed the 20210811-errors branch from 9c57b1b to aae8923 Compare August 11, 2021 14:10
Copy link
Copy Markdown
Contributor

@ajwerner ajwerner left a comment

Choose a reason for hiding this comment

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

schema :lgtm:

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @mberhault)

Copy link
Copy Markdown
Contributor

@nvb nvb left a comment

Choose a reason for hiding this comment

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

kv and storage :lgtm:

Reviewed 3 of 22 files at r1, 1 of 3 files at r3, all commit messages.
Reviewable status: :shipit: complete! 2 of 0 LGTMs obtained (waiting on @mberhault)

@miretskiy miretskiy requested a review from mberhault August 11, 2021 20:50
Copy link
Copy Markdown
Contributor

@miretskiy miretskiy left a comment

Choose a reason for hiding this comment

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

doctor says :lgtm:

Reviewable status: :shipit: complete! 3 of 0 LGTMs obtained (waiting on @mberhault)

Copy link
Copy Markdown
Contributor

@mberhault mberhault left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r4, all commit messages.
Reviewable status: :shipit: complete! 3 of 0 LGTMs obtained (waiting on @knz)

// received).
if unexpectedResp, err := stream.Recv(); err != io.EOF {
return errors.Errorf("%s: expected EOF, got resp=%v err=%v", to, unexpectedResp, err)
return errors.Wrapf(err, "%s: expected EOF, got resp=%v", to, unexpectedResp)
Copy link
Copy Markdown
Collaborator

@stevendanna stevendanna Aug 12, 2021

Choose a reason for hiding this comment

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

I haven't looked at the possible returns of stream.Recv(); but this might be problematic if err == nil since errors.Wrapf will return nil in that case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Woah, good catch

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@knz knz force-pushed the 20210811-errors branch from aae8923 to c3ce73c Compare August 12, 2021 09:48
@knz
Copy link
Copy Markdown
Contributor Author

knz commented Aug 12, 2021

@jeffswenson still waiting for your look at the proxy changes

Copy link
Copy Markdown
Contributor

@jaylim-crl jaylim-crl left a comment

Choose a reason for hiding this comment

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

sqlproxyccl changes :lgtm: cc: @cockroachdb/sqlproxy-prs

Reviewed 1 of 1 files at r5, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (and 3 stale) (waiting on @stevendanna)

@knz
Copy link
Copy Markdown
Contributor Author

knz commented Aug 12, 2021

bors r=mberhault,adityamaru,miretskiy,stevendanna,jaylim-crl,ajwerner,nvanbenschoten

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Aug 12, 2021

Build failed:

@knz
Copy link
Copy Markdown
Contributor Author

knz commented Aug 12, 2021

flake on #68795

When constructing an error from another error, it is generally
erroneous to use `Errorf("...%v", err)`: this deconstructs the
original error back to a simple string and loses all its details.

It also makes the original error opaque to redactability, to be
considered an unsafe string, even if the original error already
contained a mix of safe and unsafe strings.

The proper approach is to use `errors.Wrap` / `errors.Wrapf`.
This preserves any embedded details inside the error object and its
redactability attributes.

This change was obtained by running the following command and fixing
up the results (i.e. test code was ignored):

```
git grep -E '(errors|fmt)\.(Errorf|Newf).*%v.*[eE]rr'|grep -v _test.go
```

Release note: None
@knz knz force-pushed the 20210811-errors branch from c3ce73c to e2cd3ae Compare August 12, 2021 11:08
@knz
Copy link
Copy Markdown
Contributor Author

knz commented Aug 12, 2021

bors r=mberhault,adityamaru,miretskiy,stevendanna,jaylim-crl,ajwerner,nvanbenschoten

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Aug 12, 2021

Build succeeded:

@craig craig bot merged commit 044a0d8 into cockroachdb:master Aug 12, 2021
@knz knz deleted the 20210811-errors branch August 16, 2021 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants