Skip to content

feat: Report application errors with details#487

Closed
erezrokah wants to merge 1 commit intocloudquery:mainfrom
erezrokah:feat/proper_error_details
Closed

feat: Report application errors with details#487
erezrokah wants to merge 1 commit intocloudquery:mainfrom
erezrokah:feat/proper_error_details

Conversation

@erezrokah
Copy link
Copy Markdown
Member

Summary

Related to #462.
Draft PR as meant to serve as an example on how to improve error reporting and handling.
I'm using errdetails but we could also write our own protobuf messages instead (don't think we should).


Use the following steps to ensure your PR is ready to be reviewed

  • Read the contribution guidelines 🧑‍🎓
  • Run go fmt to format your code 🖊
  • Lint your changes via golangci-lint run 🚨 (install golangci-lint here)
  • Update or add tests 🧪
  • Ensure the status checks below are successful ✅

@github-actions github-actions bot added the feat label Dec 11, 2022
if err != nil {
return fmt.Errorf("failed to CloseAndRecv client: %w", err)
st := status.Convert(err)
errorWithDetails := err.Error()
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm concatenating errors into one string, but we can decide to do something else

s.Logger.Error().Err(err).Msg("failed to unmarshal resource. failed to wait for plugin")
errWithDetails := addErrorDetails(errors.New("failed to unmarshal resource"), unmarshalError.Error())
if writeError := eg.Wait(); writeError != nil {
errWithDetails = addErrorDetails(errors.New("plugin write failed and failed to unmarshal resource"), writeError.Error())
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Details is an array so we can send multiple errors

return nil
}
return ctx.Err()
return addErrorDetails(errors.New("context error"), ctxError.Error())
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is only an example, we should be using #486 instead

@github-actions
Copy link
Copy Markdown

github-actions bot commented Dec 11, 2022

⏱️ Benchmark results

Comparing with 8dcbe8d

  • DefaultConcurrency-2 resources/s: 11,694 ⬆️ 8.40% increase vs. 8dcbe8d
  • Glob-2 ns/op: 145.2 ⬇️ 7.23% decrease vs. 8dcbe8d
  • TablesWithChildrenDefaultConcurrency-2 resources/s: 30,881 ⬆️ 10.93% increase vs. 8dcbe8d
  • BufferedScanner-2 ns/op: 10.04 ⬆️ 5.33% increase vs. 8dcbe8d
  • LogReader-2 ns/op: 30.53 ⬇️ 0.59% decrease vs. 8dcbe8d

@erezrokah erezrokah force-pushed the feat/proper_error_details branch from f6bb7f0 to 0de7daa Compare December 11, 2022 15:40
_, err = saveClient.CloseAndRecv()
if err != nil {
return fmt.Errorf("failed to CloseAndRecv client: %w", err)
st := status.Convert(err)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We should probably put this into a function and replace #477 so we can get both the message and the details

st := status.Convert(err)
errorWithDetails := st.Message()
if len(st.Details()) > 0 {
errorWithDetails += "\nDetails:\n"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we just utilize prototext?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We can try good catch. Please note this is only one example on how to report the errors. We might want to do something else than strings concatenation

@erezrokah erezrokah force-pushed the feat/proper_error_details branch from 0de7daa to bfa9acf Compare December 21, 2022 09:06
@erezrokah
Copy link
Copy Markdown
Member Author

Closing this POC for now

@erezrokah erezrokah closed this Jan 1, 2023
@erezrokah erezrokah deleted the feat/proper_error_details branch January 1, 2023 09:44
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.

2 participants