Skip to content

Commit 20f8e04

Browse files
committed
chore(cli): prettier manifest enforcement errors
Signed-off-by: Sam Gammon <[email protected]>
1 parent 6522293 commit 20f8e04

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

packages/cli/src/main/kotlin/elide/tool/cli/AbstractToolCommand.kt

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package elide.tool.cli
1515

1616
import com.github.ajalt.clikt.core.BaseCliktCommand
17+
import com.github.ajalt.mordant.rendering.TextColors
1718
import java.util.concurrent.Callable
1819
import java.util.concurrent.atomic.AtomicBoolean
1920
import java.util.concurrent.atomic.AtomicInteger
@@ -25,6 +26,7 @@ import elide.tool.cli.err.AbstractToolError
2526
import elide.tool.cli.state.CommandOptions
2627
import elide.tool.cli.state.CommandState
2728
import elide.tooling.cli.Statics
29+
import elide.tooling.project.PackageManifestService
2830

2931
typealias CommandScope = CoroutineScope
3032

@@ -179,11 +181,26 @@ abstract class AbstractToolCommand<Context>:
179181
if (err != null && HandledExit.isHandledExit(err)) {
180182
throw err // re-throw for outer
181183
}
182-
val stack = err?.stackTrace?.joinToString("\n") ?: "(unknown)"
183-
val label = err ?: "(unknown)"
184-
logging.error("Uncaught fatal exception: $label\n$stack")
184+
val (emitStackAndLog, rethrow) = when (err) {
185+
null -> true to true
186+
is PackageManifestService.ManifestInvalid -> {
187+
if (Statics.noColor) {
188+
logging.error(err.message)
189+
} else {
190+
logging.error(TextColors.red(err.message ?: "Project manifest error"))
191+
}
192+
193+
false to false
194+
}
195+
else -> true to true
196+
}
197+
if (emitStackAndLog) {
198+
val stack = err?.stackTrace?.joinToString("\n") ?: "(unknown)"
199+
val label = err ?: "(unknown)"
200+
logging.error("Uncaught fatal exception: $label\n$stack")
201+
}
185202
exit.set(1)
186-
if (err != null) throw err
203+
if (err != null && rethrow) throw err
187204
}
188205
}
189206
}

packages/tooling/src/main/kotlin/elide/tooling/project/PackageManifestService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public interface PackageManifestService {
4646
public val valid: Boolean
4747

4848
public fun throwIfFailed(): Unit = when (this) {
49-
is ManifestErrors -> error("Failed to load project: ${errors.joinToString(", ")}")
49+
is ManifestErrors -> throw errors.first()
5050
ManifestValid -> Unit
5151
}
5252

0 commit comments

Comments
 (0)