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

Add warning to widgets when column is missing #427

Merged

Conversation

Clebal
Copy link
Contributor

@Clebal Clebal commented Jun 9, 2022

image

  • Implemented InvalidColumnError to throw it when the column used is invalid.
  • Used InvalidColumnError to throw errors in stats.js and features.worker.js.
  • Adapted HistogramWidget minMax fetching and useWidgetFetch to handle InvalidColumnError.

@shortcut-integration
Copy link

@Clebal Clebal marked this pull request as ready for review June 9, 2022 14:32
@coveralls
Copy link
Collaborator

coveralls commented Jun 9, 2022

Pull Request Test Coverage Report for Build 2489152843

  • 13 of 19 (68.42%) changed or added relevant lines in 5 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.1%) to 72.404%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/react-api/src/api/stats.js 1 2 50.0%
packages/react-api/src/api/common.js 2 4 50.0%
packages/react-core/src/utils/InvalidColumnError.js 2 5 40.0%
Totals Coverage Status
Change from base Build 2487994355: -0.1%
Covered Lines: 1600
Relevant Lines: 2072

💛 - Coveralls

@Clebal Clebal requested a review from zbigg June 13, 2022 13:28
@Clebal Clebal changed the title Add warning to widgets when used column is [sc-234842] Add warning to widgets when used column is missing Jun 13, 2022
@Clebal Clebal changed the title Add warning to widgets when used column is missing Add warning to widgets when column is missing Jun 13, 2022
this.name = NAME;
}

static is(error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know.

This whole mechanism of detecting type of exception by details of how react-workers pass errors seems fishy.

First of all, this is not "general" check for InvalidColumnError, but only for errors from worker which seem to have "Uncaught ${error.name} ..." injected at beginning of message.

It would be really better to have error codes, and proper error propagation between workers and main thread.

Anyway, i. am worried that all errors throws by "remote" api calls don't have "Uncaught: InvalidColumnError" prefix and thus don't pass this test ... and as result don't trigger warning.


modelFn.mockRejectedValue(
new InvalidColumnError('Uncaught InvalidColumnError: Invalid column')
);
Copy link
Contributor

@zbigg zbigg Jun 13, 2022

Choose a reason for hiding this comment

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

As per comment above, please add test for "new InvalidColumnError("whatever") - those errors will be thrown by "fromRemote" calls as they will go through dealWithApiError error handling

Copy link
Contributor

Choose a reason for hiding this comment

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

I've just changed this error to ' new InvalidColumnError('FooBar')' and it fails to show warning.

static message =
'The column selected for this widget is no longer available in the data source.';

constructor(message) {
Copy link
Contributor

@zbigg zbigg Jun 13, 2022

Choose a reason for hiding this comment

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

My proposition would be to change this to

super(`ERR_INVALID_COLUMN: ${message || default}`)

and in is just test for existence of 'ERR_INVALID_COLUMN: ' in error message.
This is still string test, but at least based on something that looks like error code and is universal and doesn't depend on particular details like adding "Uncaught..." by particular runtime.


export class InvalidColumnError extends Error {
static message =
'The column selected for this widget is no longer available in the data source.';
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: i don't think message copy belongs to "react-core" and exception type, it's purely widgets & UI matter (and it's used only once there) so maybe move it there?

This should be in [useWidgetFetch.js] (or in UI component).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It used in @carto/react-api also.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, now I read it correctly. I can move the message to the useWidgetFetch, ok.

Clebal added 4 commits June 13, 2022 16:27
…mn-is' of github.com:CartoDB/carto-react into feature/sc-234842/add-warning-to-widgets-when-used-column-is
Copy link
Contributor

@zbigg zbigg left a comment

Choose a reason for hiding this comment

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

LGTM :)

@Clebal Clebal merged commit 3ab5e85 into master Jun 13, 2022
@Clebal Clebal deleted the feature/sc-234842/add-warning-to-widgets-when-used-column-is branch June 13, 2022 14:49
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.

3 participants