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

Molecules that throw exceptions break use, getMol and getScope #61

Closed
loganvolkers opened this issue May 27, 2024 · 1 comment · Fixed by #59 or #62
Closed

Molecules that throw exceptions break use, getMol and getScope #61

loganvolkers opened this issue May 27, 2024 · 1 comment · Fixed by #59 or #62
Labels
bug Something isn't working

Comments

@loganvolkers
Copy link
Member

Given a molecule that throws an exception

export const LibaryMolecule = molecule(() => {
  const configMol = use(ConfigScope);
  if (!configMol)
    throw new Error("This molecule requires ConfigScope to function!");

  const config = use(configMol) as Config;
  const derivedAtom = atom((get) => get(config.example).toUpperCase());

  return {
    ...config,
    derivedAtom,
  };
});

When the molecule is used, then any subsequent calls to use or getMol or getScope will fail.

@loganvolkers loganvolkers added the bug Something isn't working label May 27, 2024
@loganvolkers
Copy link
Member Author

Affects all Bunshi versions since the introduction of use in version 2.1.0

loganvolkers added a commit that referenced this issue May 27, 2024
## Description of the change

Updates the internals of `injector` to make it gracefully handle broken
molecules, instead of leaving `use` in a broken state. Fixes #61

## Type of change

- [x] Bug fix (non-breaking change that fixes an issue)
- [ ] New feature (non-breaking change that adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] Documentation or Development tools (readme, specs, tests, code
formatting)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging a pull request may close this issue.

1 participant