From d8b067b549f90fc57f295debe40eccb4145e795c Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 6 Jun 2025 14:04:44 +0200 Subject: [PATCH] repl: Don't wait on incomplete parses from imported file Fixes #13332. --- src/libcmd/repl.cc | 24 +++++++++++++----------- tests/functional/repl.sh | 6 ++++++ 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/libcmd/repl.cc b/src/libcmd/repl.cc index 07968fa43..75a0baebc 100644 --- a/src/libcmd/repl.cc +++ b/src/libcmd/repl.cc @@ -158,6 +158,8 @@ static std::ostream & showDebugTrace(std::ostream & out, const PosTable & positi return out; } +MakeError(IncompleteReplExpr, ParseError); + static bool isFirstRepl = true; ReplExitStatus NixRepl::mainLoop() @@ -205,16 +207,8 @@ ReplExitStatus NixRepl::mainLoop() default: unreachable(); } - } catch (ParseError & e) { - if (e.msg().find("unexpected end of file") != std::string::npos) { - // For parse errors on incomplete input, we continue waiting for the next line of - // input without clearing the input so far. - continue; - } else { - printMsg(lvlError, e.msg()); - } - } catch (EvalError & e) { - printMsg(lvlError, e.msg()); + } catch (IncompleteReplExpr &) { + continue; } catch (Error & e) { printMsg(lvlError, e.msg()); } catch (Interrupted & e) { @@ -837,7 +831,15 @@ Expr * NixRepl::parseString(std::string s) void NixRepl::evalString(std::string s, Value & v) { - Expr * e = parseString(s); + Expr * e; + try { + e = parseString(s); + } catch (ParseError & e) { + if (e.msg().find("unexpected end of file") != std::string::npos) + // For parse errors on incomplete input, we continue waiting for the next line of + // input without clearing the input so far. + throw IncompleteReplExpr(e.msg()); + } e->eval(*state, *env, v); state->forceValue(v, v.determinePos(noPos)); } diff --git a/tests/functional/repl.sh b/tests/functional/repl.sh index 762636e44..015d296d5 100755 --- a/tests/functional/repl.sh +++ b/tests/functional/repl.sh @@ -277,6 +277,12 @@ testReplResponseNoRegex ' } ' +# Don't prompt for more input when getting unexpected EOF in imported files. +testReplResponse " +import $testDir/lang/parse-fail-eof-pos.nix +" \ +'.*error: syntax error, unexpected end of file.*' + # TODO: move init to characterisation/framework.sh badDiff=0 badExitCode=0