Skip to content
This repository was archived by the owner on Aug 12, 2022. It is now read-only.

fix!: Diagnostic cleanup#418

Closed
shimonp21 wants to merge 3 commits intocloudquery:mainfrom
shimonp21:error_no_errors
Closed

fix!: Diagnostic cleanup#418
shimonp21 wants to merge 3 commits intocloudquery:mainfrom
shimonp21:error_no_errors

Conversation

@shimonp21
Copy link
Contributor

Summary

[This PR is split into multiple commits, please review them separately]

This commit includes some significant improvements to how error-handling is done in cloudquery.
Most importantly - it disallows conversion of Diagnostics (or 'Diagnostic', or 'BaseError') to 'error'.
Implicit conversion between diags and errors caused many hard to track bugs (e.g. an empty list of diagnostics becoming
an 'error: no errors').

This commit also:

  • Removes 'IgnoreError' completely. This was kind of dead code - errors marked as ignored could be overwritten and become warnings if the ErrorClassidfier classified them as warnings. This happened through a very convoluted flow converting between diags and errors several times, causing messages such as "warning: cloudquery ignored an error: access denied", instead of a much more straightforward "warning: access denied".

    • When upgrading a provider to this SDK version, make sure to move any 'ignores' that you require to the ErrorClassifier (i.e. classify them as 'IGNORED' severity).
  • Changes 'ErrorClassifier' to just receive a single 'error'. It moves all the implicit information that uesd to be passed by creating a diag with context (e.g. resourceID) and passing it to the classifier, to just being explicit parameters. Some more cleanup may be a good idea here. So, the task of an errorClassifier is more straigtforward now - receive an error, convert it to a diagnostic.

See the corresponding cq-provider-aws PR for an example of how upgrade the SDK to this version.


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 ✅

shimonp21 added 3 commits July 8, 2022 16:14
The code inside the defaultErrorClassifier was never actually executed, because it was always passed a 'diag', but the first line in defaultErrorClassifier was "if err type is diag, return nil".

In any case, it's definitely better not to classify a single error twice. A more reasonable implementation might be to 'fall back to default classifier, if specific classifier returned nil', but for now, let's just remove it.
This commit includes some significant improvements to how error-handling is done in cloudquery.
Most importantly - it disallows conversion of Diagnostics (or 'Diagnostic', or 'BaseError') to 'error'.
Implicit conversion between diags and errors caused many hard to track bugs (e.g. an empty list of diagnostics becoming
an 'error: no errors').

This commit also:
- Removes 'IgnoreError' completely. This was kind of dead code - errors marked as ignored could be overwritten and become warnings if the ErrorClassidfier classified them as warnings. This happened through a very convoluted flow converting between diags and errors several times, causing messages such as "warning: cloudquery ignored an error: access denied", instead of a much more straightforward "warning: access denied".
  - When upgrading a provider to this SDK version, make sure to move any 'ignores' that you require to the ErrorClassifier (i.e. classify them as 'IGNORED' severity).

- Changes 'ErrorClassifier' to just receive a single 'error'. It moves all the implicit information that uesd to be passed by creating a diag with context (e.g. resourceID) and passing it to the classifier, to just being explicit parameters. Some more cleanup may be a good idea here. So, the task of an errorClassifier is more straigtforward now - receive an error, convert it to a diagnostic.

See the correspoing cq-provider-aws PR for an example of how upgrade the SDK to this version.
@shimonp21 shimonp21 requested review from a team, roneli, yevgenypats and zagronitay and removed request for a team July 11, 2022 08:21
@shimonp21 shimonp21 changed the title Error no errors breaking!: Fix "error: no errors" Jul 11, 2022
@shimonp21 shimonp21 changed the title breaking!: Fix "error: no errors" fix!: "error: no errors" Jul 11, 2022
// Deprecated! Only here for backward compatibility (specifically in the gRPC protocol). Do not use unless
// you are 100% sure you need this.
// Converts a list of diagnostics into an error.
func (diags Diagnostics) DeprecatedToError() string {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
func (diags Diagnostics) DeprecatedToError() string {
func (diags Diagnostics) ToError() string {

Would just mark it as Deprecated: as described in here (The Deprecated! usage above is also non standard)

@shimonp21 shimonp21 changed the title fix!: "error: no errors" fix!: Diagnostic cleanup Jul 11, 2022
@yevgenypats
Copy link
Contributor

I'll wait a bit with this PR to give a shot at removing Diags completely and only using logging mechanism.

@yevgenypats
Copy link
Contributor

Closing in favour of #437

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants