-
-
Notifications
You must be signed in to change notification settings - Fork 374
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
throw Result.Failure
for prettier error messages
#3406
base: main
Are you sure you want to change the base?
Conversation
f7dedcb
to
0c0fd7c
Compare
I'm not sure if we want to do this in the general case, since the lack of stack trace may well make things harder to debug. For low frequency errors in uncommon code paths, having the stack trace present seems preferable to me |
@lihaoyi I left only the ones that are clearly user errors, the |
Calling |
Sounds good. We need to be careful with throwing |
TBH, I lack a clear opinion on this change. I tend to hesitate, though. What I don't like is that it blurs the purpose of the API. Before, |
I'm aware of So, I propose to remove exception from |
I know you are already aware of it, but let's clarify for other people reading. def foo = T {
if (bar()) { Result.Success("result") }
else { Result.Failure("failure") }
} vs def foo = T {
if (bar()) { "result" }
else { throw Result.Failure("failure") }
} However, having the possibility to throw a |
@lolgab I think you made a good case for the motivation of So essentially, the motivation is to bypass the type inference of the compiler, which no longer can apply an For example, what about the task context API? We could use a |
@lefou the original idea was to provide an easier way to short circuit return nice error messages. Working with TBH I'm not totally confident that it definitely will be the right thing to do, but it seems plausible enough. So when I needed such a "nice" API in #3330 I went and added this capability (or tried to, and failed and so @lolgab ended up fixing it haha) |
I guess I need to point something out. I'm not against having an return/fail-mechanism based on exceptions! I'm against reusing the existing |
I could also imagine some try-catch-block in the implicit conversion from |
I'm indifferent as to what we call it. If you think it should be a separate TaskFailureException, rather than reusing Result.Failure, that works for me |
Going to this route, I would also reconsider having def foo: T[String] = T {
Result.Exception(new Exception("BOOM"), new Result.OuterStack(Seq.empty))
} which is not a great API to expose. If we want to separate the return API from the exception API, then |
I'd be ok with refactoring the |
I'm open to the name/fqn of the new Exception we want to introduce as replacement for |
@@ -68,7 +68,7 @@ trait ZincWorkerUtil { | |||
|
|||
def scalaJSBinaryVersion(scalaJSVersion: String): String = scalaJSVersion match { | |||
case _ if scalaJSVersion.startsWith("0.6.") => | |||
throw new Exception("Scala.js 0.6 is not supported") | |||
throw Result.Failure("Scala.js 0.6 is not supported") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about introducing the discussed mill.api.ResultFailureException extends MillException
as part of this PR, and throw it instead of Result.Failure
?
We can add any automatic lifting of it into a Result.Failure
and some convenience API in a separate PR.
Removed `Exception` from `Result.Failing` hierarchy. It was added after the last release, so this should be considered a binary compatible change. The `T.fail` shortcut is an experiment. Pease comment WDYT. This change was discussed in #3406
Removed `Exception` from `Result.Failing` hierarchy. It was added after the last release, so this should be considered a binary compatible change. The `T.fail` shortcut is an experiment. Pease comment WDYT. This change was discussed in #3406
Since now
Result.Failure
has a special catcher which allows to show errors the same as if they were returned asResult[T]
, we can start throwResult.Failure
s instead of genericException
s for errors.Pull Request: #3406