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

ScalafmtDynamic: add config path to unknown errors #2837

Merged
merged 1 commit into from
Oct 30, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -138,20 +138,13 @@ final case class ScalafmtDynamic(
Right(ScalafmtReflect.current)
else
resolveFormatter(configPath, version)
config <- parseConfig(configPath, fmtReflect)
config <- fmtReflect.parseConfig(configPath).toEither.left.map {
case ex: ScalafmtDynamicError => ex
case ex => new UnknownConfigError(configPath, ex)
}
} yield config
}

private def parseConfig(
configPath: Path,
fmtReflect: ScalafmtReflect
): FormatEval[ScalafmtReflectConfig] = {
Try(fmtReflect.parseConfig(configPath)).toEither.left.map {
case ex: ScalafmtDynamicError => ex
case ex => UnknownError(ex)
}
}

private def resolveFormatter(
configPath: Path,
version: ScalafmtVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ object ScalafmtDynamicError {
extends ConfigError(configPath, s"Invalid version: $version")
with NoStackTrace

class UnknownConfigError(configPath: Path, cause: Throwable)
extends ConfigError(configPath, "unknown error", cause)

case class UnknownError(cause: Throwable)
extends ScalafmtDynamicError("unknown error", cause)
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,14 @@ case class ScalafmtReflect(
}
}

def parseConfig(path: Path): ScalafmtReflectConfig = {
def parseConfig(path: Path): Try[ScalafmtReflectConfig] =
parseConfigPost300(path)
.map { configured =>
new ScalafmtReflectConfig(this, configured.invoke("get"), classLoader)
}
.recoverWith { case ReflectionException(e) =>
Failure(new ScalafmtDynamicError.ConfigParseError(path, e.getMessage))
}
.get
}

private def parseConfigPost300(path: Path): Try[Object] = {
// scalafmt >= 3.0.0
Expand Down