Skip to content

limitedLabelsCompact does ignore maxwidth argument (logged call stack is too long) #29

@aryoda

Description

@aryoda

The unit test in the file test_build_log_output.R shows that the printed stack trace shows more characters per call than maxwidth is demanding, e. g. look into the expected values of the file build_log_output_test_data_2.txt. Call number 4 has more than 1000 characters in the output (which is way too much for logging it):

Full call stack:
  1 tryLog(log("abc"))
  2 tryLog.R#49: tryCatchLog(expr = expr, dump.errors.to.file = dump.errors.to.file, error = function(e) {
        msg <- conditionMessage(e)
        invisible(structure(msg, class = "try-error", condition = e))
    }, silent.warnings = silent.warnings, silent.messages = silent.messages)
  3 tryCatchLog.R#135: tryCatch(withCallingHandlers(expr, error = function(e) {
        call.stack <- sys.calls()
        {
            .doTrace(browser())
            log.message <- e$message
        }
        if (dump.errors.to.file == TRUE) {
            dump.file.name <- format(Sys.time(), format = "dump_%Y%m%d_%H%M%S")
            utils::dump.frames()
            save.image(file = paste0(dump.file.name, ".rda"))
            log.message <- paste0(log.message, "\nCall stack environments dumped into file: ", dump.file.name, ".rda")
        }
        log.entry <- build.log.entry(names(futile.logger::ERROR), log.message, call.stack, 1)
        log.msg <- buildLogMessage(log.message, call.stack, 1)
        append.to.last.tryCatchLog.result(log.entry)
        futile.logger::flog.error(log.msg)
    }, warning = function(w) {
        call.stack <- sys.calls()
        log.entry <- build.log.entry(names(futile.logger::WARN), w$message, call.stack, 1)
        log.msg <- buildLogMessage(w$message, call.stack, 1)
        append.to.last.tryCatchLog.result(log.entry)
        futile.logger::flog.warn(log.msg)
        if (silent.warnings) {
            invokeRestart("muffleWarning")
        }
        else {
        }
    }, message = function(m) {
        call.stack <- sys.calls()
        log.entry <- build.log.entry(names(futile.logger::INFO), m$message, call.stack, 1)
        log.msg <- buildLogMessage(m$message, call.stack, 1)
        append.to.last.tryCatchLog.result(log.entry)
        futile.logger::flog.info(log.msg)
        if (silent.messages) {
            invokeRestart("muffleMessage")
        }
        else {
        }
    }), ..., finally = finally)
  4 tryCatchList(expr, classes, parentenv, handlers)

The default value of maxwidth is getOption("width") - 5L which is 129 minus 5 = 124.

The problem is the missing assignment in the line strtrim(value, maxwidth).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions