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

Throw a descriptive error when a component throws during initialization #27

Open
skulptur opened this issue Jun 25, 2020 · 2 comments
Open

Comments

@skulptur
Copy link
Contributor

What I would really like is something like React's error boundaries but I have no clue how that could work. So if it is easy to implement just catching on init, I think that would already make a big difference since when components fail it is often at that point.

Ideally we would clearly indicate the name of the component that failed and that it happened on initialization.

@skulptur
Copy link
Contributor Author

Btw might be nice to provide a way to fallback, but less important I think.

@ThaNarie
Copy link
Member

The try/catch is already in place, along with all relevant information (mostly the name, and html element):

// we don't want an error in one component to stop creating all other components
try {
const instance = new BlockConstructor(element);
setComponentInstance(displayName, { instance, element });
newInstances.push(instance);
} catch (error) {
// eslint-disable-next-line no-console
console.error(error);

Would be fairly easy to add a more descriptive error message there.

Providing a fallback can be registered on the component itself statically (since it cannot be constructed), although we have to find a uniform way to render/replace the HTML, and how/if we make that interactive.

Another option could be to configure it globally, and/or when calling initComponents. Globally is tricky though, since there is no scope/context, it's just a function to be called. We might need to introduce a global muban namespace (which is already hacked in to store the created component instances).

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