Skip to content

sql,*: error handling improvements#35821

Merged
craig[bot] merged 9 commits intocockroachdb:masterfrom
knz:20190316-annotate
Mar 18, 2019
Merged

sql,*: error handling improvements#35821
craig[bot] merged 9 commits intocockroachdb:masterfrom
knz:20190316-annotate

Conversation

@knz
Copy link
Copy Markdown
Contributor

@knz knz commented Mar 16, 2019

Subsumes #35825.
Subsumes #35820.

This PR replaces uses of errors.New, errors.Errorf and errors.Wrap by their pgerror equivalents. It also embeds the subsumed PRs; see those PR's discussion for details.

@knz knz requested review from a team, RaduBerinde, jordanlewis and madelynnblue March 16, 2019 12:29
@knz knz requested a review from a team as a code owner March 16, 2019 12:29
@knz knz requested review from a team March 16, 2019 12:29
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@knz knz force-pushed the 20190316-annotate branch 2 times, most recently from 4d371a4 to 695d7aa Compare March 16, 2019 13:25
craig bot pushed a commit that referenced this pull request Mar 16, 2019
35824: sqlbase: fix invalid uses of `pgerorr.NewErrorf` r=knz a=knz

This goes alongside #35821.
It's not valid to pass an opaque string as the `format` argument of a formatting function.

Also, wrap long lines.

Release note: None

Co-authored-by: Raphael 'kena' Poss <knz@cockroachlabs.com>
... like it had always been intended.

Release note: None
Copy link
Copy Markdown
Member

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

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

LGTM. This is great, thank you for the patience to go through all these!

@knz
Copy link
Copy Markdown
Contributor Author

knz commented Mar 17, 2019

Note to self: before this merges review the CCL code too.

knz added 3 commits March 17, 2019 10:23
The `depth` argument wasn't incremented properly, causing one level to
be lost.

Release note: None
We wish to embed stack traces in Sentry reports for internal errors.
However, since internal errors flow through RPCs as protobufs and
raven.Stacktrace objects (used for Sentry reports) do not have a
protobuf encoding, we want another serialization format.

This patch provides this by means of an encapsulation of
`raven.Stacktrace` as `log.StackTrace`, with working `Encode`/`Decode`
methods.

Release note: None
This patch splits `log.SendCrashReport` into the following pieces:

- `log.ShouldSendReport` tests whether a report should be assembled+sent;
- `log.SendReport` sends a report from a message and zero or more
  reportalbe objects.
- `log.ReportableObject` aliases `raven.Interface` and is instantiated by:
  - `log.NewReportableMessage()` for simple strings.
  - `log.NewException()` for string + stack trace.

Release note: None
@knz knz force-pushed the 20190316-annotate branch from 695d7aa to 7f0471d Compare March 17, 2019 11:59
@knz knz requested a review from a team as a code owner March 17, 2019 11:59
@knz knz requested a review from a team March 17, 2019 11:59
@knz knz force-pushed the 20190316-annotate branch from 7f0471d to 058d089 Compare March 17, 2019 22:31
@knz knz requested a review from a team March 17, 2019 22:31
@knz knz force-pushed the 20190316-annotate branch 4 times, most recently from cb01838 to 02c30ae Compare March 18, 2019 00:35
knz added 4 commits March 18, 2019 01:55
This patch achieves the following:

- it extends the pgerror.Error object with a new field `SafeDetail`,
  aimed to contain non-PII details and thuis suitable for inclusion in
  reporting.

- it populates the scrubbed format + safe
  arguments of error messages in `SafeDetail` using the same logic as
  `log.ReportablesToSafeError`.

- it captures the stack trace in `SafeDetail` but also `Detail` so
  that a human user seeing the error can report the stack trace with a
  manually created issue.

- it extends `pgerror.Wrapf()` so as to combine details in an existing
  error with the details of the point that calls `pgerror.Wrapf()`.

- it provides a custom `fmt.Formatter` for `pgerror.Error`, so that:

  - `%#v` will now print the pg error code in addition to the message;
  - `%+v` will now print the source, code, message and stored `SafeDetail`.

Release note: None
This patch ensures that a sentry report is created when a pg error
with CodeInternalError flows out of the execution layers.

Release note: None
This patch adds a linter to prevent uses of `errors.Wrapf` in `sql`
and sub-packages, to promote use of `pgerror.Wrapf` and
`pgerror.NewAssertionErrorWithWrappedErrf` instead.

It also replaces all the uses of `errors.Wrap`/`Wrapf` accordingly,
removes a few uses of `panic()`, and adds a few calls to
`pgerror.NewAssertionErrorf`.

Release note: None
@knz knz force-pushed the 20190316-annotate branch from 02c30ae to 8cfcbb4 Compare March 18, 2019 00:56
@knz knz changed the title sql*: use pgerror.{Wrapf,NewAssertionError*} where appropriate sql,*: error handling improvements Mar 18, 2019
@knz
Copy link
Copy Markdown
Contributor Author

knz commented Mar 18, 2019

This ship is sailing 🌊

bors r+

craig bot pushed a commit that referenced this pull request Mar 18, 2019
35821: sql,*: error handling improvements r=knz a=knz

Subsumes #35825.
Subsumes #35820.

This PR replaces uses of `errors.New`, `errors.Errorf` and `errors.Wrap` by their `pgerror` equivalents. It also embeds the subsumed PRs; see those PR's discussion for details.

Co-authored-by: Raphael 'kena' Poss <knz@cockroachlabs.com>
@craig
Copy link
Copy Markdown
Contributor

craig bot commented Mar 18, 2019

Build succeeded

@craig craig bot merged commit 8cfcbb4 into cockroachdb:master Mar 18, 2019
@knz knz deleted the 20190316-annotate branch March 18, 2019 07:10
knz added a commit to knz/cockroach that referenced this pull request Mar 21, 2019
This an oversight in cockroachdb#35821 - all the errors in `inbound.go` use
`errors.Wrap`, this one must too.

(This and the rest of the file should really use `pgerror.Wrap`, which
in combination with cockroachdb#36023 would be innocuous. But that's an aside.)
In either case, all the functionality in this file requires wrapping,
not flattening the error into a string.

Release note: None
@bdarnell
Copy link
Copy Markdown
Contributor

bdarnell commented Jul 8, 2019

I think this PR was too eager to replace Wrapfs with NewAssertionErrors. Specifically the ones in schema_changer.go occur in the context of a client.Txn where the error (or its cause) is inspected. This replaces potentially-retriable errors with assertion errors which can cause schema changes to fail unnecessarily.

I'll fix the ones that I'm specifically finding to be problems, but it makes me nervous to see how many Wrapfs were replaced with assertion errors instead of using the new Wrapf.

bdarnell added a commit to bdarnell/cockroach that referenced this pull request Jul 9, 2019
The AssertionError wrappers hid the retryable nature of the errors,
causing failures in cases that should have been retried.

Most of the affected wrappers were changed from Wrapf to
NewAssertionError in cockroachdb#35821. I looked at all uses of
NewAssertionErrorWithWrappedErrf and changed all the ones where a
client.Txn was in scope unless they were clearly not going to be
txn-related (for example, proto unmarshaling errors).

Release note (bug fix): Transaction retries in schema changes are
again handled correctly.
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.

4 participants