From b3792cbae57acb12d1262e0de51ca879efaf5624 Mon Sep 17 00:00:00 2001 From: Bobby Grayson Date: Fri, 9 Oct 2026 08:29:39 -0400 Subject: [PATCH] be-js: report an unconfigured library instead of throwing `temper run -b js` looked the library up with `getValue` before checking anything, so a `--library` that names no library, or one whose config file does not parse, ended in an uncaught Kotlin exception: Exception in thread "main" java.util.NoSuchElementException: Key no-such-library is missing in the map. at lang.temper.be.js.RunJsKt.runJsBestEffort(RunJs.kt:69) The metadata lookup right below it already returns a CliFailure for a library the build does not know, as py, lua and java do. The `getValue` threw first. A plain `get` lets that check run; the config is only read for its library name, which is null-safe already. Now: ## exception.msg: No JS library name for RunLibraryRequest(libraryName=no-such-library, taskName=run) Run failed RunTest.runJsBackendUnknownLibrary runs the `run` input with a library name it does not have. Before this change it fails with the NoSuchElementException; after, the run reports failure. Fixes #611. Co-Authored-By: Claude Opus 5.5 (1M context) Signed-off-by: Bobby Grayson --- .../kotlin/lang/temper/be/js/RunJs.kt | 3 ++- .../test/kotlin/lang/temper/cli/RunTest.kt | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/be-js/src/commonMain/kotlin/lang/temper/be/js/RunJs.kt b/be-js/src/commonMain/kotlin/lang/temper/be/js/RunJs.kt index 978713063..50a682d2e 100644 --- a/be-js/src/commonMain/kotlin/lang/temper/be/js/RunJs.kt +++ b/be-js/src/commonMain/kotlin/lang/temper/be/js/RunJs.kt @@ -65,8 +65,9 @@ internal fun runJsBestEffort( when (request) { is RunBackendSpecificCompilationStepRequest -> error("$request") is RunLibraryRequest -> { + // Null for a library the build does not know, which the metadata check below reports. mainLibraryConfig = dependencies.libraryConfigurations - .byLibraryName.getValue(request.libraryName) + .byLibraryName[request.libraryName] val jsLibraryName = dependencies.metadata[request.libraryName, JsMetadataKey.JsLibraryName] ?: return listOf( ToolchainResult(result = RFailure(CliFailure("No JS library name for $request"))), diff --git a/cli/src/test/kotlin/lang/temper/cli/RunTest.kt b/cli/src/test/kotlin/lang/temper/cli/RunTest.kt index 9b192c1bf..e1f2b59fb 100644 --- a/cli/src/test/kotlin/lang/temper/cli/RunTest.kt +++ b/cli/src/test/kotlin/lang/temper/cli/RunTest.kt @@ -31,6 +31,7 @@ import kotlin.test.Ignore import kotlin.test.Test import kotlin.test.assertContains import kotlin.test.assertEquals +import kotlin.test.assertFalse import kotlin.test.assertTrue class RunTest { @@ -106,6 +107,26 @@ class RunTest { @Test fun runJsBackend() = runRunTest("run", JsBackend.Factory.backendId) + @Test + fun runJsBackendUnknownLibrary() { + val path = resourcePath("/run/input") + // Clean up in case someone ran a build in the source tree. + removeDirRecursive(path.resolve(TEMPER_OUT_NAME)) + runWithTemporaryDirCopyOf("RunJsBackendUnknownLibrary", path) { tempDir -> + val result = doRun( + RunTask( + backends = setOf(JsBackend.Factory.backendId), + request = RunLibraryRequest( + DashedIdentifier.from("no-such-library")!!, + taskName = "RunJsBackendUnknownLibrary", + ), + ), + workRoot = tempDir, + ) + assertFalse(result.ok) + } + } + @Ignore("Reexamine how import strategy and run tasks affect running only cherry-picked modules") @Test fun runJsBackendTop() = runRunTest("runTopLevel", JsBackend.Factory.backendId)