Skip to content

[Bioc-devel] best practice for storing long error message in R package

2 messages · Hervé Pagès, Dan Tenenbaum

#
Hi Mike,

Not saying this is best practice but personally I like to keep the error
message close to the function itself. This makes maintenance easier as
otherwise it would be easy to forget to update the error message when
the behavior of the function is changed.

.foo_very_long_error_msg <- c(
     "This is a very long error message etc etc ",
     "etc etc etc ",
     "etc etc etc ",
     ...
)

foo <- function(...)
{
     ...
     if (...)
         stop(wmsg(.foo_very_long_error_msg))
     ...
}

wmsg() is a little helper defined in S4Vectors that wraps the error
message to fit in a console of width getOption("width").

Just my 2 cents.

H.
On 03/09/2016 07:19 AM, Michael Love wrote:

  
    
#
Staying out of the debate as to whether to emit a long error message or direct the user to the relevant man page, I will say that whether the error message is long or short, it should still direct the user to the relevant man page, where the way to avoid the error should be discussed in full. That way the careful user who reads documentation will find out how to avoid the error before actually encountering it.

Dan


----- Original Message -----