[education/rkward] rkward/rbackend: Fix marking error message as error level
Thomas Friedrichsmeier
null at kde.org
Wed Sep 3 06:48:52 BST 2025
Git commit 9fcd6d18cd8ca7d3b9d8a3928fdfe7c07e7b73ec by Thomas Friedrichsmeier.
Committed on 01/09/2025 at 16:23.
Pushed by tfry into branch 'master'.
Fix marking error message as error level
M +6 -9 rkward/rbackend/rkrbackend.cpp
M +1 -1 rkward/rbackend/rkrinterface.cpp
M +2 -4 rkward/rbackend/rpackages/rkward/R/internal.R
https://invent.kde.org/education/rkward/-/commit/9fcd6d18cd8ca7d3b9d8a3928fdfe7c07e7b73ec
diff --git a/rkward/rbackend/rkrbackend.cpp b/rkward/rbackend/rkrbackend.cpp
index ad5c246c9..7a459bf00 100644
--- a/rkward/rbackend/rkrbackend.cpp
+++ b/rkward/rbackend/rkrbackend.cpp
@@ -250,11 +250,11 @@ int RReadConsole(const char *prompt, unsigned char *buf, int buflen, int hist) {
} else if (RKRBackend::repl_status.user_command_status == RKRBackend::RKReplStatus::UserCommandTransmitted) {
if (RKRBackend::repl_status.user_command_completely_transmitted) {
// fully transmitted, but R is still asking for more, without signalling R_Busy? This looks like an incomplete statement.
- // HOWEVER: It may also have been an empty statement such as " ", so let's check whether the prompt looks like a "continue" prompt
+ // HOWEVER: It may also have been a (trailing) empty statement such as "\n", so let's check whether the prompt looks like a "continue" prompt
RBusy(1); // Mark command as "running"
if (RKTextCodec::fromNative(prompt) == RKRSupport::SEXPToString(RFn::Rf_GetOption(RFn::Rf_install("continue"), ROb(R_BaseEnv)))) {
RKRBackend::this_pointer->current_command->status |= RCommand::Failed | RCommand::ErrorIncomplete;
- RKRBackend::repl_status.user_command_status != RKRBackend::RKReplStatus::ReplIterationKilled;
+ RKRBackend::repl_status.user_command_status = RKRBackend::RKReplStatus::ReplIterationKilled;
RFn::Rf_error("%s", ""); // to discard the buffer
} // else: continue in next iteration at UserCommandRunning
} else {
@@ -262,9 +262,9 @@ int RReadConsole(const char *prompt, unsigned char *buf, int buflen, int hist) {
return 1;
}
} else if (RKRBackend::repl_status.user_command_status == RKRBackend::RKReplStatus::UserCommandSyntaxError) {
+ RBusy(1); // properly init command, so commandFinished() can end it
RKRBackend::this_pointer->current_command->status |= RCommand::Failed | RCommand::ErrorSyntax;
RKRBackend::repl_status.user_command_status = RKRBackend::RKReplStatus::NoUserCommand;
- if (RKRBackend::repl_status.user_command_parsed_up_to <= 0) RKRBackend::this_pointer->startOutputCapture(); // HACK: No capture active, but commandFinished() will try to end one
RKRBackend::this_pointer->commandFinished();
} else if (RKRBackend::repl_status.user_command_status == RKRBackend::RKReplStatus::UserCommandRunning) {
// This can mean three different things:
@@ -759,6 +759,9 @@ void RResetConsole() {
}
}
} else if (RKRBackend::repl_status.user_command_status != RKRBackend::RKReplStatus::ReplIterationKilled) {
+ // "error:" is just a placeholder. The desired effect is to promote latest "Warning" output to Error-level (in RInterface)
+ auto msg = u"error:"_s;
+ RKRBackend::this_pointer->handleOutput(msg, msg.length(), ROutput::Error);
RK_DEBUG(RBACKEND, DL_DEBUG, "error in user command");
}
}
@@ -912,9 +915,6 @@ SEXP doSimpleBackendCall(SEXP _call) {
}
i++;
}
- } else if (call == QStringLiteral("error")) { // capture error message
- doError(list.value(1));
- return ROb(R_NilValue);
} else if (call == QStringLiteral("tempdir")) {
return (RKRSupport::StringListToSEXP(QStringList(RKRBackendProtocolBackend::dataDir())));
} else if (call == QLatin1String("home")) {
@@ -1610,9 +1610,6 @@ void RKRBackend::initialize(const QString &locale_dir, bool setup) {
if (!runDirectCommand(versioncheck + u"\n"_s)) lib_load_fail = true;
if (!runDirectCommand(QStringLiteral(".rk.fix.assignments ()\n"))) sink_fail = true;
- // error/output sink and help browser
- if (!runDirectCommand(QStringLiteral("options (error=quote (.rk.do.error ()))\n"))) sink_fail = true;
-
QString error_messages;
if (lib_load_fail) {
error_messages.append(i18n("</p>\t- The 'rkward' R-library either could not be loaded at all, or not in the correct version. This may lead to all sorts of errors, from single missing features to complete failure to function. The most likely cause is that the last installation did not place all files in the correct place. However, in some cases, left-overs from a previous installation that was not cleanly removed may be the cause.</p>\
diff --git a/rkward/rbackend/rkrinterface.cpp b/rkward/rbackend/rkrinterface.cpp
index 69ab2217b..8df7b22ea 100644
--- a/rkward/rbackend/rkrinterface.cpp
+++ b/rkward/rbackend/rkrinterface.cpp
@@ -491,7 +491,7 @@ void RInterface::flushOutput(bool forced) {
// An error output is typically just the copy of the previous output, so merge if possible
if (command->output_list.isEmpty()) {
command->output_list.append(output);
- } else if (command->output_list.last().output == output.output) {
+ } else {
command->output_list.last().type = ROutput::Error;
continue; // don't call command->newOutput(), again!
}
diff --git a/rkward/rbackend/rpackages/rkward/R/internal.R b/rkward/rbackend/rpackages/rkward/R/internal.R
index b5862e448..e9eeae26f 100755
--- a/rkward/rbackend/rpackages/rkward/R/internal.R
+++ b/rkward/rbackend/rpackages/rkward/R/internal.R
@@ -119,10 +119,8 @@
#' @export
".rk.do.error" <- function () {
-# comment in R sources says, it may not be good to query options during error handling. But what can we do, if R_ShowErrorMessages is not longer exported?
- if (getOption ("show.error.messages")) {
- .rk.call.backend("error", geterrmessage())
- }
+ # NOTE: cannot use "warning", here
+ print("NOTE: 'options(error=.rk.do.error)' is no longer needed, and .rk.do.error will be removed in a future version of RKWard.")
}
# C call into the backend process only
More information about the rkward-tracker
mailing list