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

throw Result.Failure for prettier error messages #3406

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions scalalib/api/src/mill/scalalib/api/ZincWorkerUtil.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package mill.scalalib.api

import mill.api.Loose.Agg
import mill.api.PathRef
import mill.api.{PathRef, Result}
import scala.util.matching.Regex

trait ZincWorkerUtil {
Expand Down Expand Up @@ -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")
Copy link
Member

@lefou lefou Aug 25, 2024

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.

case ScalaJSFullVersion(major, minor, patch, suffix) =>
if (suffix != null && minor == "0" && patch == "0")
s"$major.$minor$suffix"
Expand All @@ -78,7 +78,7 @@ trait ZincWorkerUtil {

def scalaJSWorkerVersion(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")
case ScalaJSFullVersion(major, _, _, _) =>
major
}
Expand Down
3 changes: 2 additions & 1 deletion scalalib/src/mill/scalalib/CrossModuleBase.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mill.scalalib

import mill.T
import mill.api.Result
import mill.define.Cross
import mill.define.Cross.Resolver
import mill.scalalib.api.ZincWorkerUtil
Expand Down Expand Up @@ -31,7 +32,7 @@ trait CrossModuleBase extends ScalaModule with Cross.Module[String] {
)
.collectFirst { case x => x }
.getOrElse(
throw new Exception(
throw Result.Failure(
s"Unable to find compatible cross version between $crossScalaVersion and " +
c.crossModules.map(_.crossScalaVersion).mkString(",")
)
Expand Down
5 changes: 2 additions & 3 deletions scalalib/src/mill/scalalib/Dep.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package mill.scalalib

import upickle.default.{macroRW, ReadWriter => RW}
import coursier.core.{Configuration, Dependency}
import mill.scalalib.CrossVersion._
import coursier.core.Dependency
import mill.scalalib.api.ZincWorkerUtil
import upickle.default.{macroRW, ReadWriter => RW}

import scala.annotation.unused
import coursier.core.Configuration

case class Dep(dep: coursier.Dependency, cross: CrossVersion, force: Boolean) {
require(
Expand Down
2 changes: 1 addition & 1 deletion scalalib/src/mill/scalalib/PublishModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ trait PublishModule extends JavaModule { outer =>
override def moduleDeps: Seq[PublishModule] = super.moduleDeps.map {
case m: PublishModule => m
case other =>
throw new Exception(
throw Result.Failure(
s"PublishModule moduleDeps need to be also PublishModules. $other is not a PublishModule"
)
}
Expand Down
2 changes: 1 addition & 1 deletion scalalib/src/mill/scalalib/ZincWorkerModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ trait ZincWorkerModule extends mill.Module with OfflineSupportModule { self: Cou
scalaCompilerBridgeJar(x, y, repositoriesTask())
.asSuccess
.getOrElse(
throw new Exception(s"Failed to load compiler bridge for $x $y")
throw Result.Failure(s"Failed to load compiler bridge for $x $y")
)
.value
)),
Expand Down
12 changes: 6 additions & 6 deletions scalalib/src/mill/scalalib/publish/SonatypeHttpApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@ import java.util.Base64
import scala.annotation.tailrec
import scala.concurrent.duration._

import mill.api.Result
import mill.main.BuildInfo
import requests.BaseSession
import ujson.ParseException
import requests.Session

class SonatypeHttpApi(
uri: String,
credentials: String,
readTimeout: Int,
connectTimeout: Int
) {
val http: Session = requests.Session(
val http: requests.Session = requests.Session(
readTimeout = readTimeout,
connectTimeout = connectTimeout,
maxRedirects = 0,
Expand All @@ -29,7 +27,9 @@ class SonatypeHttpApi(
"Authorization" -> s"Basic $base64Creds",
"Accept" -> "application/json",
"Content-Type" -> "application/json",
"User-Agent" -> s"mill-${BuildInfo.millVersion}${BaseSession.defaultHeaders.get("User-Agent").map(" (" + _ + ")").getOrElse("")}"
"User-Agent" -> s"mill-${BuildInfo.millVersion}${requests.BaseSession.defaultHeaders.get(
"User-Agent"
).map(" (" + _ + ")").getOrElse("")}"
)

// https://oss.sonatype.org/nexus-staging-plugin/default/docs/path__staging_profiles.html
Expand Down Expand Up @@ -67,7 +67,7 @@ class SonatypeHttpApi(
try {
ujson.read(response.text())("type").str
} catch {
case e: ParseException =>
case e: ujson.ParseException =>
throw new RuntimeException(
s"Could not parse HTTP response. ${e.getMessage()}" + "\n" + s"Raw response: ${response}",
e
Expand Down
Loading