10000 Split out `Result` and `ExecResult` types, replace `Either[String, T]` with `Result` by lihaoyi · Pull Request #4528 · com-lihaoyi/mill · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Split out Result and ExecResult types, replace Either[String, T] with Result #4528

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

Merged
merged 28 commits into from
Feb 11, 2025

Conversation

lihaoyi
Copy link
Member
@lihaoyi lihaoyi commented Feb 11, 2025

Fixes #4527

Result should hopefully provide a simple user-facing result type, replacing the extensive use of Either[String, T] throughout the codebase. ExecResult models the internals of the exec/ module and really shouldn't be used elsewhere.

Exactly how rich to make the Result type is uncertain; this PR's Either[String, T] version is easy and simple, but it's arguable whether we want Either[Err, T] to be able to hold non-string errors, or Either[List[String], T] to be able to aggregate multiple errors (which we currently discard and pick the first one most of the time). But such changes can happen in future PRs any time before 0.13.0 is released

For now I just got rid of ExecResult.Failure#value: Option[T]. We weren't using it anywhere but in unit tests, and it wasn't really suitable to downstream use by users AFAICT. We probably need to come up with a different way to e.g. gather data from failing test results, but this one probably was a failed experiment

@lihaoyi lihaoyi marked this pull request as ready for review February 11, 2025 05:50
val outerStack = new mill.api.Result.OuterStack(base.getStackTrace)
Left(mill.api.Result.Exception(e, outerStack).toString)
}
class Exception(val error: String) extends java.lang.Exception(error)
Copy link
Member

Choose a reason for hiding this comment

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

Some ScalaDoc would be nice. What's the purpose of and when to use this exception?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is meant to replace the Result.Failure extends Exception we wanted to get rid of. I'll add Scaladoc later, I expect this to evolve significantly

@lihaoyi lihaoyi merged commit ab3f836 into com-lihaoyi:main Feb 11, 2025
29 of 31 checks passed
@lefou lefou added this to the 0.13.0 milestone Feb 11, 2025
@lefou lefou added the post-review-required A merged PR which has still open comments or questions, which need to be clarified label May 19, 2025
Comment on lines +16 to +21
// val (doneMsg, testResults) = res
// testResults
// .groupBy(_.fullyQualifiedName)
// .view
// .mapValues(_.map(e => e.selector -> e).toMap)
// .toMap
Copy link
Member

Choose a reason for hiding this comment

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

This and some other tests were commented out. We should revisit this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
post-review-required A merged PR which has still open comments or questions, which need to be clarified
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Split up mill.api.Result
2 participants
0