Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display accurate message for INACCESSIBLE_SCHEMA error #7157

Merged
merged 11 commits into from May 14, 2024

Conversation

fredzqm
Copy link
Contributor

@fredzqm fredzqm commented May 10, 2024

Description

  1. Interpret and handle INACCESSIBLE_SCHEMA from the backend. Print accurate error message. In practice, INACCESSIBLE_SCHEMA should occur rarely:
    • CSQL was just created or in the middle of a restart.
    • CSQL is down or overloaded.
    • Switch to a new CSQL database, so no chance to establish connectivity.
  2. Make sure errors from LRO are handled properly. Tested with running firebase deploy after deleting the P4SA IAM user, so INCOMPATIBLE_SCHEMA error are returned in Apply after provisioning connectivity.

There was a subtle typo s/orignal/original, failed with:
Screenshot 2024-05-09 at 8 54 06 PM

Scenarios Tested

firebase sql:migrate:diff when schema is accessible vs not.
Screenshot 2024-05-09 at 8 02 31 PM

Sample Commands

@fredzqm fredzqm changed the title Print inaccessible schema error in a different way Display accurate message for INACCESSIBLE_SCHEMA error May 10, 2024
@fredzqm fredzqm changed the base branch from master to dataconnect May 10, 2024 18:00
const incompatible = incompatibles[0];
// Extract the violation type from the precondition error detail.
const preconditionErrs = errorDetails(err, PRECONDITION_ERROR_TYPESTRING);
incompatible.violationType = preconditionErrs[0].violations[0].type;
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems fragile to future changes - are we sure that we'll always return only one precondition error detail (maybe)? Are we sure that it will always contain exactly 1 violation (probably not)?

Would prefer something at least like like:

if (preconditonErrs.length) {
const preconditionErr = preconditionErrs[0]
incompatible.violationType = preconditonErr.violations.some(v => v.type === "INACCESSIBLE_SCHEMA") ? "INACCESSIBLE_SCHEMA" : "INCOMPATIBLE_SCHEMA";
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is true right now. If backend returns IncompatibleSqlSchemaError, the first PreconditionFailure should be that.

Though you made a good point on future changes. Let me make it detect the first violation type that match.

}
break;
default:
throw new FirebaseError("Unknown schema violation type: " + error.violationType);
Copy link
Contributor

Choose a reason for hiding this comment

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

Include the error message here too - if this ever get hit, it will be very helpful to have it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, at this point, we don't have access to the original error message. I can include the whole diff error detail here.

src/dataconnect/types.ts Outdated Show resolved Hide resolved
Copy link
Contributor Author

@fredzqm fredzqm left a comment

Choose a reason for hiding this comment

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

Addressed feedbacks and tested again

const incompatible = incompatibles[0];
// Extract the violation type from the precondition error detail.
const preconditionErrs = errorDetails(err, PRECONDITION_ERROR_TYPESTRING);
incompatible.violationType = preconditionErrs[0].violations[0].type;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is true right now. If backend returns IncompatibleSqlSchemaError, the first PreconditionFailure should be that.

Though you made a good point on future changes. Let me make it detect the first violation type that match.

}
break;
default:
throw new FirebaseError("Unknown schema violation type: " + error.violationType);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, at this point, we don't have access to the original error message. I can include the whole diff error detail here.

@joehan joehan merged commit 2a4ee46 into dataconnect May 14, 2024
32 checks passed
joehan added a commit that referenced this pull request May 20, 2024
* Cloud SQL create and update polish (#7159)

* improve logged message execute SQL commands (#7156)

* Error handling and logging when linking CSQL instance (#7158)

* Display accurate message for INACCESSIBLE_SCHEMA error (#7157)

* handle INACCESSIBLE_SCHEMA case separately

* error msg

* m

* m

* m

* merge

* feedbacks

* Jh idx no metadata calls (#7179)

* Avoid triggering metadata server calls in idx

* Remove outdated service account check

* Update Firebase Logo (#7180)

* unleash turtles (#7174)

* unleash turtles

* Update CHANGELOG.md

* Flag flip for gen kit (#7175)

* Flag flip for gen kit

* Update CHANGELOG.md

* update icons

---------

Co-authored-by: Bryan Kendall <bkend@google.com>
Co-authored-by: joehan <joehanley@google.com>

* Use client instead of size 1 pool (#7182)

* Fix schema validation (#7185)

* Fix schema validation

* Also depend on redhat.yaml

* fix typo

---------

Co-authored-by: Fred Zhang <fredzqm@google.com>
Co-authored-by: Harold Shen <hlshen@google.com>
Co-authored-by: Bryan Kendall <bkend@google.com>
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.

None yet

2 participants