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

Fix failed assertion for unknown app server errors #6783

Merged
merged 14 commits into from
Jul 28, 2023

Conversation

michael-wb
Copy link
Contributor

@michael-wb michael-wb commented Jul 12, 2023

What, How & Why?

If an unknown error is received from the server, the current AppUtils::check_for_errors() function will attempt to create an AppError using the ErrorCodes::UnknownError value, which does not have the runtime_error or app_error error category, leading to an assertion failure when the AppError is constructed.

This code updates the error code value when UnknownError is returned from the ErrorCodes::from_string() function to use the "generic" ErrorCodes::AppServerError. The server_error string value was added to the AppError class for storing the original error code string returned from the server.

Added an AppError test to cover all the paths for creating an AppError in AppUtils::check_for_errors().

In a separate PR, the plan is to update this function so all errors returned from the server will create an AppError with code AppServerError and the specific error details will be contained in the "server_error" and "reason" strings.

Fixes #6758

☑️ ToDos

  • 📝 Changelog update
  • 🚦 Tests (or not relevant)
  • [ ] C-API, if public C++ API changed.

@cla-bot cla-bot bot added the cla: yes label Jul 12, 2023
@michael-wb michael-wb changed the title Prevent failed assertion for unknown server app errors Prevent failed assertion for unknown app server errors Jul 12, 2023
@michael-wb michael-wb force-pushed the mwb/handle-unknown-app-errors branch from 4c16d3b to b3ac96c Compare July 12, 2023 14:06
@michael-wb michael-wb changed the title Prevent failed assertion for unknown app server errors Fix failed assertion for unknown app server errors Jul 12, 2023
@michael-wb michael-wb force-pushed the mwb/handle-unknown-app-errors branch from b3ac96c to 95fc4c9 Compare July 12, 2023 18:50
@@ -88,7 +88,7 @@ ErrorCategory ErrorCodes::error_categories(Error code)
case StaleAccessor:
case WrongThread:
case WrongTransactionState:
return ErrorCategory().set(ErrorCategory::logic_error);
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these actually runtime errors? Would it make more sense to just make AppError inherit from Exception rather than adding basically all other kinds of errors to RuntimeError?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I reverted these changes and made AppError inherit from Exception like you recommended.
I kept the AppServiceError error code as a way to report App errors that the client doesn't know about.

@michael-wb michael-wb requested a review from jbreams July 26, 2023 21:13
.set(ErrorCategory::runtime_error)
.set(ErrorCategory::app_error)
.set(ErrorCategory::custom_error);
return ErrorCategory().set(ErrorCategory::app_error).set(ErrorCategory::custom_error);
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I must have not been clear, in my past comment I was suggesting just not changing any of the existing error categories or which codes fall into what but making the AppError inherit from Exception so it doesn't have to only be RuntimeErrors.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I thought I was reverting the changes back. I'll fix these.

REALM_ASSERT(ErrorCodes::error_categories(code).test(ErrorCategory::app_error));
}

AppError::AppError(std::string server_err, std::string message, std::string link,
Copy link
Collaborator

Choose a reason for hiding this comment

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

you could make server_err optional and then have only one constructor

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

@michael-wb michael-wb merged commit ab4c2f1 into master Jul 28, 2023
@michael-wb michael-wb deleted the mwb/handle-unknown-app-errors branch July 28, 2023 19:23
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The app crashed due to an error in the serverless function
3 participants