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

try() function #3137

Merged
merged 2 commits into from
Mar 29, 2024
Merged

try() function #3137

merged 2 commits into from
Mar 29, 2024

Conversation

berekuk
Copy link
Collaborator

@berekuk berekuk commented Mar 29, 2024

Fixes #3108.

@berekuk berekuk requested a review from OAGr as a code owner March 29, 2024 02:50
Copy link

changeset-bot bot commented Mar 29, 2024

🦋 Changeset detected

Latest commit: 978658c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@quri/squiggle-lang Patch
@quri/squiggle-components Patch
@quri/prettier-plugin-squiggle Patch
@quri/versioned-squiggle-components Patch
vscode-squiggle Patch
@quri/squiggle-textmate-grammar Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Mar 29, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
quri-hub ✅ Ready (Inspect) Visit Preview Mar 29, 2024 2:57am
quri-ui ✅ Ready (Inspect) Visit Preview Mar 29, 2024 2:57am
squiggle-components ✅ Ready (Inspect) Visit Preview Mar 29, 2024 2:57am
squiggle-website ✅ Ready (Inspect) Visit Preview Mar 29, 2024 2:57am

[
frNamed("fn", frLambdaTyped([], frAny({ genericName: "A" }))),
// in the future, this function could be called with the error message
frNamed("fallbackFn", frLambdaTyped([], frAny({ genericName: "A" }))),
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 that we should use a generic like this here.

As a user, I'd probably be inclined to use a different type in a lot of cases.

Like, try({|| 2+''}, {|| {type: error, message: "X failed" })

Copy link
Collaborator Author

@berekuk berekuk Mar 29, 2024

Choose a reason for hiding this comment

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

Yeah, technically the output type should be a union of both functions' return types, but we don't have unions in frTypes.

Copy link
Contributor

Choose a reason for hiding this comment

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

What about frOr()?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, you're right, I forgot about it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fixed here: 22f7435

// This doesn't looks like an error in user code, treat it as fatal
throw e;
}
return reducer.call(fallbackFn, []);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we'll want to catch the error later, but we don't need that now. Maybe we make a new formal error type.

@OAGr
Copy link
Contributor

OAGr commented Mar 29, 2024

Fairly basic - but as you know, I'm a fan of iterating in lots of steps! So, kudos for finding a way to get a lot of the value with minimal functionality.

Can improve later. I might change the Generics issue, but can do that later.

@OAGr OAGr merged commit 0e9ce5a into main Mar 29, 2024
6 checks passed
@OAGr OAGr deleted the try-catch branch March 29, 2024 18:27
@github-actions github-actions bot mentioned this pull request May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Simple raise/catch error handling
2 participants