Replies: 9 comments 26 replies
-
I added one |
Beta Was this translation helpful? Give feedback.
-
Alternatively we could use the error value directly without needing to panic/recover? func CopyFile(src, dst string) (err error) {
wrapped := func(err) error {
return fmt.Errorf("copy %s %s: %w", src, dst, err)
}
r := try.To1(&err, os.Open(src), wrapped)
defer r.Close()
cleanup := func(err) error {
_ = os.Remove(dst)
}
w := try.To1(&err, os.Create(dst), wrapped, cleanup)
defer w.Close()
try.To1(&err, io.Copy(w, r), wrapped)
return nil
} |
Beta Was this translation helpful? Give feedback.
-
I have been able to implement the following on my fork: func(src, dst string) (err error) {
defer err2.Handlef(&err, "copy %s %s", src, dst)
r := try.Check1(os.Open(src))
defer r.Close()
rmFile := try.Cleanup(func() {
os.Remove(dst)
})
w := try.Try1(os.Create(dst))(rmFile, try.Fmt("os.Create %s", dst))
defer w.Close()
try.Try1(io.Copy(w, r))(rmFile)
return nil
} |
Beta Was this translation helpful? Give feedback.
-
Actually handlers aren't given directly to |
Beta Was this translation helpful? Give feedback.
-
One reason not to use variadic functions is performance. Because Go's generics don't support them, you would need to use reflection or type assertion, which is extremely slow. It's n x 10x slower than without it. When The second reason is that you cannot freely mix variadic input and multiple return values. |
Beta Was this translation helpful? Give feedback.
-
I am still learning generics, so I might be off-base here, but the point is basically that the existing API uses |
Beta Was this translation helpful? Give feedback.
-
I would appreciate feedback on the API of my fork- the point is to not have separate |
Beta Was this translation helpful? Give feedback.
-
I am hopefully done with my fork now and I renamed the package to err3 now.
Thanks for the great inspiration and code and test cases to make this possible. It was a lot easier to fork and make what I wanted then to convince you to change how things work. But I am willing to collaborate in ways that we agree make sense to lessen the forking or improve |
Beta Was this translation helpful? Give feedback.
-
Hi, I thought that I let you know that your "feature request" is now possible. However, one: defer err2.Handle(&err) is needed per function where error handling is happening. But now Now, every Zig error handling feature is supported by the |
Beta Was this translation helpful? Give feedback.
-
Is it possible to have an API that does not rely on defer like the following?
Beta Was this translation helpful? Give feedback.
All reactions