[Rd] Error message truncation

Michael Chirico mich@elchirico4 @ending from gm@il@com
Fri May 18 05:27:13 CEST 2018


Help pages for stop/warning reference the option "warning.length", e.g.
from ?stop:

Errors will be truncated to getOption("warning.length") characters, default
> 1000.


Essentially the same is in ?warning.

Neither of these mention the hard-coded limits on the acceptable values of
this option in options.c
<https://github.com/wch/r-source/blob/a7356bf91b511287aacd3a992abfbcb75b60d93c/src/main/options.c#L546-L552>
:

if (streql(CHAR(namei), "warning.length")) {
  int k = asInteger(argi);
  if (k < 100 || k > 8170)
  error(_("invalid value for '%s'"), CHAR(namei));
  R_WarnLength = k;
  SET_VECTOR_ELT(value, i, SetOption(tag, argi));
}

Further, it appears there's a physical limit on the length of the error
message itself which is only slightly larger than 8170:

set.seed(1023)
NN = 10000L
str = paste(sample(letters, NN, TRUE), collapse = '')
# should of course be 10000
tryCatch(stop(str), error = function(e) nchar(e$message))
# [1] 8190

My questions are:


   - Can we add some information to the help pages indicating valid values
   of options('warning.length')?
   - Is there any way to increase the limit on error message length? I
   understand having such a limit is safer than potentially crashing a system
   that wants to print a massive error string.

This came up in relation to this SO Q&A:

https://stackoverflow.com/a/50387968/3576984

The user is submitting a database query; the error message will first
reproduce the entirety of the query and then give some diagnostic
information. Queries can get quite long, so it stands to reason that this
8190-length limit might be binding.

Thanks,
Michael Chirico

	[[alternative HTML version deleted]]



More information about the R-devel mailing list