Skip to content

Commit 5dd3559

Browse files
Add custom exception and throw it when node not found in the path (#2323)
* Add custom exception and throw it when node not found in the path * Fix running integration test --------- Co-authored-by: piotr-sekula <[email protected]>
1 parent 579189a commit 5dd3559

File tree

4 files changed

+40
-18
lines changed

4 files changed

+40
-18
lines changed

modules/build/src/main/scala/scala/build/internal/Runner.scala

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,7 @@ import java.nio.file.{Files, Path, Paths}
1111

1212
import scala.build.EitherCps.{either, value}
1313
import scala.build.Logger
14-
import scala.build.errors.{
15-
NoFrameworkFoundByBridgeError,
16-
NoTestFrameworkFoundError,
17-
NoTestsRun,
18-
TestError,
19-
TooManyFrameworksFoundByBridgeError
20-
}
14+
import scala.build.errors._
2115
import scala.build.testrunner.{AsmTestRunner, TestRunner}
2216
import scala.util.{Failure, Properties, Success}
2317

@@ -232,11 +226,11 @@ object Runner {
232226
jsDom: Boolean = false,
233227
sourceMap: Boolean = false,
234228
esModule: Boolean = false
235-
): Process = {
229+
): Either[BuildException, Process] = either {
236230

237231
import logger.{log, debug}
238232

239-
val nodePath = findInPath("node").fold("node")(_.toString)
233+
val nodePath = value(findInPath("node").map(_.toString).toRight(NodeNotFoundError()))
240234

241235
if (!jsDom && allowExecve && Execve.available()) {
242236

modules/cli/src/main/scala/scala/cli/commands/run/Run.scala

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -456,15 +456,17 @@ object Run extends ScalaCommand[RunOptions] with BuildCommandHelpers {
456456
if (showCommand)
457457
Left(Runner.jsCommand(outputPath.toIO, args, jsDom = jsDom))
458458
else {
459-
val process = Runner.runJs(
460-
outputPath.toIO,
461-
args,
462-
logger,
463-
allowExecve = allowExecve,
464-
jsDom = jsDom,
465-
sourceMap = build.options.scalaJsOptions.emitSourceMaps,
466-
esModule = esModule
467-
)
459+
val process = value {
460+
Runner.runJs(
461+
outputPath.toIO,
462+
args,
463+
logger,
464+
allowExecve = allowExecve,
465+
jsDom = jsDom,
466+
sourceMap = build.options.scalaJsOptions.emitSourceMaps,
467+
esModule = esModule
468+
)
469+
}
468470
process.onExit().thenApply(_ => if (os.exists(jsDest)) os.remove(jsDest))
469471
Right((process, None))
470472
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package scala.build.errors
2+
3+
final class NodeNotFoundError extends BuildException(
4+
"The Node was not found on the PATH. Please ensure that Node is installed correctly and then try again"
5+
)

modules/integration/src/test/scala/scala/cli/integration/RunScalaJsTestDefinitions.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,27 @@ trait RunScalaJsTestDefinitions { _: RunTestDefinitions =>
3131
simpleJsTest("--js-mode", "release")
3232
}
3333

34+
test("without node on the PATH") {
35+
val fileName = "simple.sc"
36+
val message = "Hello"
37+
val inputs = TestInputs(
38+
os.rel / fileName ->
39+
s"""import scala.scalajs.js
40+
|val console = js.Dynamic.global.console
41+
|val msg = "$message"
42+
|console.log(msg)
43+
|""".stripMargin
44+
)
45+
inputs.fromRoot { root =>
46+
val thrown = os.proc(TestUtil.cli, extraOptions, fileName, "--js", "--server=false")
47+
.call(cwd = root, env = Map("PATH" -> "", "PATHEXT" -> ""), check = false, mergeErrIntoOut = true)
48+
val output = thrown.out.trim()
49+
50+
assert(thrown.exitCode == 1)
51+
assert(output.contains("Node was not found on the PATH"))
52+
}
53+
}
54+
3455
test("JS arguments") {
3556
val inputs = TestInputs(
3657
os.rel / "simple.sc" ->

0 commit comments

Comments
 (0)