Skip to content

Commit

Permalink
Add trailing newline if missing from messages
Browse files Browse the repository at this point in the history
  • Loading branch information
lionel- committed Nov 23, 2023
1 parent df01dde commit da5fe14
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion crates/ark/src/modules/public/errors.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,31 @@
return()
}

msg <- conditionMessage(cnd)

# Add trailing newline if there isn't one, including for the length 0
# case. See https://github.com/posit-dev/positron/issues/1878.
#
# This is to accomodate base message which may or may not have an
# explicit trailing newline, see the `appendLF` argument of
# `message()`. Because other message emitters might conform to the
# behaviour of `warning()` and `stop()` which never add newlines, we
# have to account for both possibility.
#
# Because of this we lose support for constructing messages within a
# single line piece by piece with `message(appendLF = FALSE)`, but
# that's an esoteric feature. If this is reported, we could do more
# specialised behaviour depending on whether the message condition is
# inherits from `"simpleMessage"` or not.
n <- nchar(msg)
if (substr(msg, n, n) != "\n") {
msg <- paste0(msg, "\n")
}

# Output the condition message to the relevant stream (normally
# stdout). Note that for historical reasons, messages include a
# trailing newline
cat(conditionMessage(cnd), file = default_message_file())
cat(msg, file = default_message_file())

# Silence default message handling
invokeRestart("muffleMessage")
Expand Down

0 comments on commit da5fe14

Please sign in to comment.