Skip to content

Commit

Permalink
Fix off by one typo in source column location (#1633)
Browse files Browse the repository at this point in the history
* Fix off by one typo in column location

* NEWS bullet
  • Loading branch information
DavisVaughan authored Jun 7, 2023
1 parent c8f3cea commit c55f602
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 31 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# rlang (development version)

* Fixed an off-by-one typo in the traceback source column location (#1633).

* `abort()` now respects the base R global option,
`options(show.error.messages = FALSE)` (#1630).

Expand Down
2 changes: 1 addition & 1 deletion R/trace.R
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ src_loc <- function(srcref) {
}

line <- srcref[[1]]
column <- srcref[[5]] - 1L
column <- srcref[[5]]

style_hyperlink(
paste0(file_trim, ":", line, ":", column),
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/cnd-message.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
(expect_error(f()))
Output
<error/rlang_error>
Error in `g()` at bar/baz/myfile.R:2:9:
Error in `g()` at bar/baz/myfile.R:2:10:
! Foo.

# inform() and warn() use fallback bullets formatting
Expand Down
58 changes: 29 additions & 29 deletions tests/testthat/_snaps/trace.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
print(trace, dir = dir)
Output
x
1. \-rlang (local) i() at test-trace.R:25:2
2. \-rlang (local) j(i) at test-trace.R:18:7
3. \-rlang (local) k(i) at test-trace.R:19:21
4. \-rlang (local) l(i) at test-trace.R:22:4
1. \-rlang (local) i() at test-trace.R:25:3
2. \-rlang (local) j(i) at test-trace.R:18:8
3. \-rlang (local) k(i) at test-trace.R:19:22
4. \-rlang (local) l(i) at test-trace.R:22:5
Code
cat("\n")
Output
Expand All @@ -25,21 +25,21 @@
Output
x
1. \-rlang (local) f()
2. \-rlang (local) g() at test-trace.R:49:20
3. +-base::tryCatch(h(), foo = identity, bar = identity) at test-trace.R:50:20
2. \-rlang (local) g() at test-trace.R:49:21
3. +-base::tryCatch(h(), foo = identity, bar = identity) at test-trace.R:50:21
4. | \-base (local) tryCatchList(expr, classes, parentenv, handlers)
5. | +-base (local) tryCatchOne(...)
6. | | \-base (local) doTryCatch(return(expr), name, parentenv, handler)
7. | \-base (local) tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
8. | \-base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
9. | \-base (local) doTryCatch(return(expr), name, parentenv, handler)
10. \-rlang (local) h()
11. +-base::tryCatch(i(), baz = identity) at test-trace.R:51:20
11. +-base::tryCatch(i(), baz = identity) at test-trace.R:51:21
12. | \-base (local) tryCatchList(expr, classes, parentenv, handlers)
13. | \-base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
14. | \-base (local) doTryCatch(return(expr), name, parentenv, handler)
15. \-rlang (local) i()
16. +-base::tryCatch(trace_back(e, bottom = 0)) at test-trace.R:52:20
16. +-base::tryCatch(trace_back(e, bottom = 0)) at test-trace.R:52:21
17. | \-base (local) tryCatchList(expr, classes, parentenv, handlers)
18. \-rlang::trace_back(e, bottom = 0)
Code
Expand All @@ -48,16 +48,16 @@
Output
x
1. \-rlang (local) f()
2. \-rlang (local) g() at test-trace.R:49:20
3. +<<-base::tryCatch(h(), foo = identity, bar = identity) at test-trace.R:50:20>>
2. \-rlang (local) g() at test-trace.R:49:21
3. +<<-base::tryCatch(h(), foo = identity, bar = identity) at test-trace.R:50:21>>
4. | <<\-base (local) tryCatchList(expr, classes, parentenv, handlers)>>
5. | <<+-base (local) tryCatchOne(...)>>
6. | <<| \-base (local) doTryCatch(return(expr), name, parentenv, handler)>>
7. | <<\-base (local) tryCatchList(expr, names[-nh], parentenv, handlers[-nh])>>
8. | <<\-base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])>>
9. | <<\-base (local) doTryCatch(return(expr), name, parentenv, handler)>>
10. \-rlang (local) h()
11. +<<-base::tryCatch(i(), baz = identity) at test-trace.R:51:20>>
11. +<<-base::tryCatch(i(), baz = identity) at test-trace.R:51:21>>
12. | <<\-base (local) tryCatchList(expr, classes, parentenv, handlers)>>
13. | <<\-base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])>>
14. | <<\-base (local) doTryCatch(return(expr), name, parentenv, handler)>>
Expand All @@ -68,7 +68,7 @@
Output
1. rlang (local) f()
2. rlang (local) g()
at test-trace.R:49:20
at test-trace.R:49:21
10. rlang (local) h()
15. rlang (local) i()

Expand All @@ -80,12 +80,12 @@
Output
x
1. \-rlang (local) f()
2. +-base::eval(quote(eval(quote(g())))) at test-trace.R:61:7
2. +-base::eval(quote(eval(quote(g())))) at test-trace.R:61:8
3. | \-base::eval(quote(eval(quote(g()))))
4. +-base::eval(quote(g()))
5. | \-base::eval(quote(g()))
6. \-rlang (local) g()
7. +-base::tryCatch(eval(quote(h())), foo = identity, bar = identity) at test-trace.R:62:7
7. +-base::tryCatch(eval(quote(h())), foo = identity, bar = identity) at test-trace.R:62:8
8. | \-base (local) tryCatchList(expr, classes, parentenv, handlers)
9. | +-base (local) tryCatchOne(...)
10. | | \-base (local) doTryCatch(return(expr), name, parentenv, handler)
Expand All @@ -101,12 +101,12 @@
Output
x
1. \-rlang (local) f()
2. +<<-base::eval(quote(eval(quote(g())))) at test-trace.R:61:7>>
2. +<<-base::eval(quote(eval(quote(g())))) at test-trace.R:61:8>>
3. | <<\-base::eval(quote(eval(quote(g()))))>>
4. +<<-base::eval(quote(g()))>>
5. | <<\-base::eval(quote(g()))>>
6. \-rlang (local) g()
7. +<<-base::tryCatch(eval(quote(h())), foo = identity, bar = identity) at test-trace.R:62:7>>
7. +<<-base::tryCatch(eval(quote(h())), foo = identity, bar = identity) at test-trace.R:62:8>>
8. | <<\-base (local) tryCatchList(expr, classes, parentenv, handlers)>>
9. | <<+-base (local) tryCatchOne(...)>>
10. | <<| \-base (local) doTryCatch(return(expr), name, parentenv, handler)>>
Expand Down Expand Up @@ -739,21 +739,21 @@
Output
x
1. \-rlang (local) f(current_env())
2. \-rlang (local) g(e) at fixtures/trace-srcref2.R:2:2
2. \-rlang (local) g(e) at fixtures/trace-srcref2.R:2:3
Code
# Focused
print_focused_trace(trace, dir = dir, srcrefs = srcrefs)
Output
x
1. \-rlang (local) f(current_env())
2. \-rlang (local) g(e) at fixtures/trace-srcref2.R:2:2
2. \-rlang (local) g(e) at fixtures/trace-srcref2.R:2:3
Code
# Branch
print(trace, simplify = "branch", dir = dir, srcrefs = srcrefs)
Output
1. rlang (local) f(current_env())
2. rlang (local) g(e)
at fixtures/trace-srcref2.R:2:2
at fixtures/trace-srcref2.R:2:3

# summary.rlang_trace() prints the full tree

Expand Down Expand Up @@ -822,14 +822,14 @@
summary(trace0)
Output
x
1. \-rlang (local) f(0) at test-trace.R:412:2
2. +-base::identity(identity(g(n))) at test-trace.R:408:7
1. \-rlang (local) f(0) at test-trace.R:412:3
2. +-base::identity(identity(g(n))) at test-trace.R:408:8
3. +-base::identity(g(n))
4. \-rlang (local) g(n)
5. +-base::identity(identity(h(n))) at test-trace.R:409:7
5. +-base::identity(identity(h(n))) at test-trace.R:409:8
6. +-base::identity(h(n))
7. \-rlang (local) h(n)
8. +-base::identity(identity(trace_back(e, bottom = n))) at test-trace.R:410:7
8. +-base::identity(identity(trace_back(e, bottom = n))) at test-trace.R:410:8
9. +-base::identity(trace_back(e, bottom = n))
10. \-rlang::trace_back(e, bottom = n)
Code
Expand All @@ -842,11 +842,11 @@
summary(trace1)
Output
x
1. \-rlang (local) f(1) at test-trace.R:413:2
2. +-base::identity(identity(g(n))) at test-trace.R:408:7
1. \-rlang (local) f(1) at test-trace.R:413:3
2. +-base::identity(identity(g(n))) at test-trace.R:408:8
3. +-base::identity(g(n))
4. \-rlang (local) g(n)
5. +-base::identity(identity(h(n))) at test-trace.R:409:7
5. +-base::identity(identity(h(n))) at test-trace.R:409:8
6. +-base::identity(h(n))
7. \-rlang (local) h(n)
Code
Expand All @@ -859,8 +859,8 @@
summary(trace2)
Output
x
1. \-rlang (local) f(2) at test-trace.R:414:2
2. +-base::identity(identity(g(n))) at test-trace.R:408:7
1. \-rlang (local) f(2) at test-trace.R:414:3
2. +-base::identity(identity(g(n))) at test-trace.R:408:8
3. +-base::identity(g(n))
4. \-rlang (local) g(n)
Code
Expand All @@ -873,7 +873,7 @@
summary(trace3)
Output
x
1. \-rlang (local) f(3) at test-trace.R:415:2
1. \-rlang (local) f(3) at test-trace.R:415:3

# caught error does not display backtrace in knitted files

Expand Down

0 comments on commit c55f602

Please sign in to comment.