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

feat(errors): add client scaffolding for custom error messages #9677

Merged
merged 1 commit into from
Apr 30, 2020

Conversation

etr2460
Copy link
Member

@etr2460 etr2460 commented Apr 29, 2020

CATEGORY

Choose one

  • Bug Fix
  • Enhancement (new features, refinement)
  • Refactor
  • Add tests
  • Build / Development Environment
  • Documentation

SUMMARY

Beginning implementation of #9194

This PR adds scaffolding for the client side part of custom error messages. No existing behavior should be changed yet. Scaffolding consists of:

  • introduce an ErrorMessageComponentRegistry for registering all error messages by error type
  • allow individual deployments to override these error messages with setupErrorMessagesExtra
  • display an error message from the registry if one exists for the given type, otherwise show the generic ErrorMessageWithStackTrace

Note that this registry is included in the main Superset repo. This is because we only support translations in this repo currently, and it's important to allow all the error messages registered here to have translations.

Todo in future PRs:

  • Add the new error object to client and backend responses
  • Introduce custom error message components

TEST PLAN

View a dashboard, ensure network errors and hardcoded raised errors still render properly

ADDITIONAL INFORMATION

  • Has associated issue:
  • Changes UI
  • Requires DB Migration.
  • Confirm DB Migration upgrade and downgrade tested.
  • Introduces new feature or API
  • Removes existing feature or API

REVIEWERS

to: @graceguo-supercat @ktmud @kristw @rusackas

message,
link,
stackTrace,
}: Props) {
const [showStackTrace, setShowStackTrace] = useState(false);

// Check if a custom error message component was registered for this message
Copy link
Member Author

Choose a reason for hiding this comment

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

this is essentially a no-op today as we haven't registered any error messages and this component will never get a new error object passed in.

@etr2460 etr2460 force-pushed the erik-ritter--error-messages-1 branch 2 times, most recently from cfdf7bb to c532ec4 Compare April 29, 2020 01:13
Copy link
Contributor

@kristw kristw left a comment

Choose a reason for hiding this comment

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

a few suggestions. non super blocking

message,
link,
stackTrace,
}: Props) {
const [showStackTrace, setShowStackTrace] = useState(false);

// Check if a custom error message component was registered for this message
const ErrorMessageComponent =
Copy link
Contributor

Choose a reason for hiding this comment

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

if (error) {
  const ErrorMessageComponent = getErrorMessageComponentRegistry().get(error.errorType);
  if (ErrorMessageComponent) {
    return <ErrorMessageComponent error={error} />
  }
}

Copy link
Contributor

Choose a reason for hiding this comment

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

can modify a bit to check for error once

Copy link
Member Author

Choose a reason for hiding this comment

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

works for me! i optimized for repetition over nesting, but i agree this is better

@@ -84,4 +85,7 @@ export default function setupApp() {
// @ts-ignore
window.jQuery = $;
require('bootstrap');

// setup appwide custom error messages
setupErrorMessages();
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure if you want to nest the call here or in App.jsx like setupApp and setupPlugins. The items in setupApp here seems likely to be removed at some point.

Copy link
Member Author

Choose a reason for hiding this comment

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

I put it here because it seems like there are a bunch of App.jsxs that exist today, and we'd want all of them to have the error message registry attached to them. I assume in the future we'll end up with only one and this file will be removed, but i think it's fine to keep this here for now

* under the License.
*/

// Generic errors created on the frontend
Copy link
Contributor

Choose a reason for hiding this comment

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

Can do this so ErrorType will also work like enum.

// Generic errors created on the frontend
// TODO: Add more error types as we classify more errors
export const ErrorType = {
  FRONTEND_CSRF_ERROR: 'FRONTEND_CSRF_ERROR',
  FRONTEND_NETWORK_ERROR: 'FRONTEND_NETWORK_ERROR',
  FRONTEND_TIMEOUT_ERROR: 'FRONTEND_TIMEOUT_ERROR',
} as const;

type ValueOf<T> = T[keyof T];

export type ErrorType = ValueOf<typeof ErrorType>;

Copy link
Member Author

Choose a reason for hiding this comment

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

done

};

export type ErrorMessageComponent =
| React.ComponentType<ErrorMessageComponentProps>
Copy link
Contributor

Choose a reason for hiding this comment

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

React.ComponentType already includes React.FunctionComponent

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps this should be enough

export type ErrorMessageComponent = ReactComponentType<ErrorMessageComponentProps>;

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@etr2460 etr2460 force-pushed the erik-ritter--error-messages-1 branch from c532ec4 to dce295f Compare April 30, 2020 00:08
@etr2460 etr2460 merged commit 5d7b135 into apache:master Apr 30, 2020
@etr2460 etr2460 added the SIP-40 label Jun 2, 2020
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.37.0 labels Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/L 🚢 0.37.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants