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

catch getWidget() exceptions thrown in render() #612

Closed
2 tasks done
u0078867 opened this issue Jun 15, 2017 · 1 comment
Closed
2 tasks done

catch getWidget() exceptions thrown in render() #612

u0078867 opened this issue Jun 15, 2017 · 1 comment

Comments

@u0078867
Copy link

u0078867 commented Jun 15, 2017

Prerequisites

  • I have read the documentation;
  • In the case of a bug report, I understand that providing a SSCCE example is tremendously useful to the maintainers.

Description

When inputting an uiSchema where ui:widget is of non-existing or non-registered type, I get the error:
No widget <widget> for type <type>, thrown by getWidget() in the render() method of some component. I would like to catch it, but I was not able either via try/catch of my component rendering <Form/> (which I do understand given the async nature or React rendering), nor by the experimental unstable_handleError() in React 15+.

Steps to Reproduce

I cannot reproduce it in the playground.

Expected behavior

Possibility to catch the un-existing widget error.

Actual behavior

An error is thrown.

Version

0.49.0

@u0078867
Copy link
Author

I understood on my own I guess: the trick (also applied in the playground example) is using a try/catch block inside a setImmediate() one, for a component wrapping <Form/>:

  componentWillReceiveProps (nextProps) {
    setImmediate(() => {
      try {
        console.log(nextProps.schema);
        console.log(nextProps.uiSchema);
        console.log(nextProps.formData);
        this.setState({
          valid: true,
          schema: nextProps.schema,
          uiSchema: nextProps.uiSchema,
          formData: nextProps.formData,
        });
      } catch (err) {
        this.setState({ valid: false });
      }
    });
  };

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

No branches or pull requests

2 participants