Merged
Conversation
aatxe
requested changes
Apr 21, 2025
batteries/result.luau
Outdated
| } | { | ||
| success: false, | ||
| traceback: string, | ||
| err: string, |
Member
There was a problem hiding this comment.
Do we want this over a form where err's type can be specified?
Contributor
Author
There was a problem hiding this comment.
Yes, kind of? The reason why is so that result failures can be appended. For example:
local function someOperation()
return result(false, "failed to do generic operation")
end
local function meow()
local call = someOperation()
if not call then
call.err = `failure in function "meow"; {call.err}`
end
end
local function meow2()
local call = someOperation()
if not call then
call.err = `failure in function "meow2"; {call.err}`
end
enderr as string is great for propagating messages. Maybe we could attach something like errMessage and err to have both? I can see the value in, say, an error tagged enum.
Co-authored-by: ariel <aweiss@hey.com>
aatxe
approved these changes
Apr 22, 2025
aatxe
approved these changes
May 4, 2025
green-real
pushed a commit
to green-real/lute
that referenced
this pull request
May 19, 2025
Many operations involving the file system & networking can fail. One of the most common ways of handling this is pcall, but this is not type safe. A common idiom is to have a Result type, somewhat similar to Rust's Result type. It's an extremely common and useful idiom. Any project written in Lute interacting with APIs which could error will end up encountering the problem of gracefully handling failure; the result battery significantly helps with that. --------- Co-authored-by: ariel <aweiss@hey.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Many operations involving the file system & networking can fail. One of the most common ways of handling this is pcall, but this is not type safe.
A common idiom is to have a Result type, somewhat similar to Rust's Result type. It's an extremely common and useful idiom. Any project written in Lute interacting with APIs which could error will end up encountering the problem of gracefully handling failure; the result battery significantly helps with that.