Skip to content

Insert newline before backtrace? #1368

Closed

Description

@hadley

I use

rlang::global_entrace()
options(rlang_backtrace_on_error = "full")

And in the interests of skimmability, I think it would be useful to add a new line between the error message and the backtrace:

shift(range(1, 10), 10)
#> ! <range> object is invalid:
#> - @end (10) must be greater than or equal to @start (11)
#> Backtrace:
#>     ▆
#>  1. └─global shift(range(1, 10), 10)
#>  2.   ├─base::`@<-`(`*tmp*`, "start", value = x@start + shift)
#>  3.   └─R7::`@<-.R7_object`(`*tmp*`, "start", value = x@start + shift)
#>  4.     └─R7::`prop<-`(`*tmp*`, nme, value = `<promise>`) at OOP-WG/R/property.R:239:2
#>  5.       └─R7::validate(object, properties = FALSE) at OOP-WG/R/property.R:203:6

->

shift(range(1, 10), 10)
#> ! <range> object is invalid:
#> - @end (10) must be greater than or equal to @start (11)
#> 
#> Backtrace:
#>     ▆
#>  1. └─global shift(range(1, 10), 10)
#>  2.   ├─base::`@<-`(`*tmp*`, "start", value = x@start + shift)
#>  3.   └─R7::`@<-.R7_object`(`*tmp*`, "start", value = x@start + shift)
#>  4.     └─R7::`prop<-`(`*tmp*`, nme, value = `<promise>`) at OOP-WG/R/property.R:239:2
#>  5.       └─R7::validate(object, properties = FALSE) at OOP-WG/R/property.R:203:6

And maybe "Backtrace" should be displayed in bold?

Activity

  1. lionel- commented on Feb 24, 2022

    @lionel-
    Member

    Or maybe --- as in yaml sectioning?

    shift(range(1, 10), 10)
    #> ! <range> object is invalid:
    #> - @end (10) must be greater than or equal to @start (11)
    #> ---
    #> Backtrace:
    #>     ▆
    #>  1. └─global shift(range(1, 10), 10)
    #>  2.   ├─base::`@<-`(`*tmp*`, "start", value = x@start + shift)
    #>  3.   └─R7::`@<-.R7_object`(`*tmp*`, "start", value = x@start + shift)
    #>  4.     └─R7::`prop<-`(`*tmp*`, nme, value = `<promise>`) at OOP-WG/R/property.R:239:2
    #>  5.       └─R7::validate(object, properties = FALSE) at OOP-WG/R/property.R:203:6
  2. hadley commented on Feb 24, 2022

    @hadley
    MemberAuthor

    I think just a blank line is a clearer distinction

  3. lionel- commented on Mar 1, 2022

    @lionel-
    Member

    I just tried it and I find a blank line is too clear a distinction, like the backtrace is not part of the same output. A --- ruler seems like a better fit. In your example it's less clear because of the leading - bullet, but that's not a very common case. What do you think about this more representative output:

    Screenshot 2022-03-01 at 08 37 38

    Also backtrace should be displayed in bold. Are you sure it isn't?

  4. lionel- commented on Mar 1, 2022

    @lionel-
    Member

    I think my concern is that blank lines are very rare in normal output so it seems too much of a separation. Blank lines would confuse the sectioning of the console between prompt+input and output.

  5. hadley commented on Mar 1, 2022

    @hadley
    MemberAuthor

    Ok, lets go with --- then, and I'll tweak the bullet I used in R7.

  6. lionel- commented on Mar 1, 2022

    @lionel-
    Member

    Another place where a --- separation creates better sectioning is last_warnings(), which prints a list of warnings + backtraces separated by newlines:

    [[11]]
    <warning/rlang_warning>
    Warning in `low3()`:
    low-level
    ---
    Backtrace:
      1. base::print(catch_error(high1(chain = FALSE, stop_helper = TRUE)))
     10. rlang high1(chain = FALSE, stop_helper = TRUE)
     11. rlang high2(...)
           at test-cnd-abort.R:226:11
     12. rlang high3(...)
           at test-cnd-abort.R:227:11
     19. rlang low1()
     20. rlang low2()
           at test-cnd-abort.R:182:10
     21. rlang low3()
           at test-cnd-abort.R:183:10
    
    [[12]]
    <warning/rlang_warning>
    Warning in `low3()`:
    low-level
    ---
    Backtrace:
      1. base::print(catch_error(high1(chain = FALSE, stop_helper = FALSE)))
     10. rlang high1(chain = FALSE, stop_helper = FALSE)
     11. rlang high2(...)
           at test-cnd-abort.R:226:11
     12. rlang high3(...)
           at test-cnd-abort.R:227:11
     19. rlang low1()
     20. rlang low2()
           at test-cnd-abort.R:182:10
     21. rlang low3()
           at test-cnd-abort.R:183:10
    
  7. added a commit that references this issue on Mar 1, 2022
    0e27186
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions