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

[core] Standardize error messages across components #520

Closed
michaldudak opened this issue Aug 2, 2024 · 1 comment · Fixed by #735
Closed

[core] Standardize error messages across components #520

michaldudak opened this issue Aug 2, 2024 · 1 comment · Fixed by #735
Labels
core Infrastructure work going on behind the scenes

Comments

@michaldudak
Copy link
Member

michaldudak commented Aug 2, 2024

Create a utility to format a message and show an error to have consistency.
The most common case for now is a missing context. Errors should be handled in hooks (use*Context), optionally allowing the context to be absent, as in:

function useMenuRootContext(optional?: false): MenuRootContext;
function useMenuRootContext(optional: true): MenuRootContext | null;
function useMenuRootContext(optional?: boolean) {
const context = React.useContext(MenuRootContext);
if (context === null && !optional) {
throw new Error('Base UI: MenuRootContext is not defined.');
}
return context;
}

Search keywords:

@michaldudak michaldudak added the core Infrastructure work going on behind the scenes label Aug 2, 2024
@colmtuite colmtuite moved this from Backlog to Selected in Base UI Alpha Sep 16, 2024
@github-project-automation github-project-automation bot moved this from Selected to Done in Base UI Alpha Oct 30, 2024
Copy link

This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue.
Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Infrastructure work going on behind the scenes
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant