-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CliException for cleaner error reporting (#1345)
- Loading branch information
Showing
9 changed files
with
116 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
core/src/main/scala/org/bykn/bosatsu/tool/CliException.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.bykn.bosatsu.tool | ||
|
||
import org.bykn.bosatsu.PlatformIO | ||
import org.typelevel.paiges.Doc | ||
|
||
import cats.syntax.all._ | ||
|
||
trait CliException { self: Exception => | ||
def errDoc: Doc | ||
def stdOutDoc: Doc | ||
def exitCode: ExitCode | ||
|
||
def report[F[_], P](platform: PlatformIO[F, P]): F[ExitCode] = { | ||
import platform.moduleIOMonad | ||
|
||
platform.writeStdout(stdOutDoc) *> | ||
platform.writeError(errDoc).as(exitCode) | ||
} | ||
} | ||
|
||
object CliException { | ||
case class Basic(summary: String, exitCode: ExitCode = ExitCode.Error) extends Exception(summary) with CliException { | ||
def stdOutDoc: Doc = Doc.empty | ||
lazy val errDoc: Doc = Doc.text(summary) | ||
} | ||
} |