Skip to content

Commit a526b39

Browse files
committed
remove attributes of rather than deparse error stack trace objects
1 parent 30219bb commit a526b39

File tree

7 files changed

+67
-68
lines changed

7 files changed

+67
-68
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#### Updates
99

10+
* 'miraiError' evaluation errors now return the call stack at `$stack.trace` as a list of calls (with srcrefs removed) without deparsing to character strings.
1011
* `mirai_map()` improvements:
1112
+ Multiple map on a dataframe or matrix now correctly preserves the row names of the input as the names of the output.
1213
+ Fixes language objects being evaluated before the map function is applied (#194).

R/mirai.R

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@
9191
#' character string of class \sQuote{miraiError} and \sQuote{errorValue}.
9292
#' \code{\link{is_mirai_error}} may be used to test for this. The elements of
9393
#' the original condition are accessible via \code{$} on the error object. A
94-
#' stack trace is also available at \code{$stack.trace}.
94+
#' stack trace comprising a list of calls is also available at
95+
#' \code{$stack.trace}.
9596
#'
9697
#' If a daemon crashes or terminates unexpectedly during evaluation, an
9798
#' \sQuote{errorValue} 19 (Connection reset) is returned.
@@ -629,11 +630,6 @@ ephemeral_daemon <- function(data, timeout) {
629630
deparse_safe <- function(x) if (length(x))
630631
deparse(x, width.cutoff = 500L, backtick = TRUE, control = NULL, nlines = 1L)
631632

632-
deparse_call <- function(call) {
633-
srcref <- attr(call, "srcref")
634-
if (is.null(srcref)) deparse_safe(call) else as.character(srcref)
635-
}
636-
637633
mk_interrupt_error <- function() .miraiInterrupt
638634

639635
mk_mirai_error <- function(e, sc) {
@@ -653,10 +649,9 @@ mk_mirai_error <- function(e, sc) {
653649
sc <- sc[(length(sc) - 1L):(idx + 1L)]
654650
if (sc[[1L]][[1L]] == ".handleSimpleError")
655651
sc <- sc[-1L]
656-
`class<-`(
657-
`attributes<-`(msg, `[[<-`(e, "stack.trace", lapply(sc, deparse_call))),
658-
c("miraiError", "errorValue", "try-error")
659-
)
652+
sc <- lapply(sc, `attributes<-`, NULL)
653+
out <- `attributes<-`(msg, `[[<-`(e, "stack.trace", sc))
654+
`class<-`(out, c("miraiError", "errorValue", "try-error"))
660655
}
661656

662657
.miraiInterrupt <- `class<-`("", c("miraiInterrupt", "errorValue", "try-error"))

man/call_mirai.Rd

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/collect_mirai.Rd

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/mirai.Rd

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/tests.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ connection && {
7272
if (!is_mirai_error(me)) test_true(is_error_value(me))
7373
if (is_mirai_error(me)) test_type("list", me$stack.trace)
7474
if (is_mirai_error(me)) test_true(length(me$stack.trace) >= 2L)
75-
if (is_mirai_error(me)) test_true(all(as.logical(lapply(me$stack.trace, is.character))))
75+
if (is_mirai_error(me)) test_true(all(as.logical(lapply(me$stack.trace, is.language))))
7676
test_true(!is_mirai_interrupt(me))
7777
test_class("errorValue", me)
7878
test_print(me)

vignettes/mirai.Rmd

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@ To wait for and collect the return value, use the mirai's `[]` method:
6262

6363
``` r
6464
m[]
65-
#> [1] 4.593301 3.547016 5.444301 5.124194 3.310823
65+
#> [1] 4.171990 4.426733 4.665712 2.957891 4.321967
6666
```
6767
As a mirai represents an async operation, it is never necessary to wait for it. Other code can continue to be run. Once it completes, the return value automatically becomes available at `$data`.
6868

6969
``` r
7070
m
7171
#> < mirai [$data] >
7272
m$data
73-
#> [1] 4.593301 3.547016 5.444301 5.124194 3.310823
73+
#> [1] 4.171990 4.426733 4.665712 2.957891 4.321967
7474
```
7575
For easy programmatic use of `mirai()`, '.expr' accepts a pre-constructed language object, and also a list of named arguments passed via '.args'. So, the following would be equivalent to the above:
7676

@@ -82,7 +82,7 @@ args <- list(time = x$time, mean = x$mean)
8282

8383
m <- mirai(.expr = expr, .args = args)
8484
m[]
85-
#> [1] 3.670071 2.977546 1.879653 4.616901 3.151703
85+
#> [1] 3.921015 4.145974 4.864750 2.311800 4.678318
8686
```
8787

8888
[&laquo; Back to ToC](#table-of-contents)
@@ -163,8 +163,8 @@ for (i in 1:10) {
163163
#> iteration 5 successful
164164
#> iteration 6 successful
165165
#> iteration 7 successful
166-
#> Error: random error
167166
#> iteration 8 successful
167+
#> Error: random error
168168
#> iteration 9 successful
169169
#> iteration 10 successful
170170
```
@@ -203,7 +203,7 @@ status()
203203
#> [1] 6
204204
#>
205205
#> $daemons
206-
#> [1] "abstract://3b94f4f4b442de8e85fb2c16"
206+
#> [1] "abstract://151135cc39a81a6e83935293"
207207
#>
208208
#> $mirai
209209
#> awaiting executing completed
@@ -237,7 +237,7 @@ status()
237237
#> [1] 6
238238
#>
239239
#> $daemons
240-
#> [1] "abstract://42fa6a9127a783f0045aab46"
240+
#> [1] "abstract://9be5c1b0df5c047fb60435f9"
241241
```
242242
This implementation sends tasks immediately, and ensures that tasks are evenly-distributed amongst daemons. This means that optimal scheduling is not guaranteed as the duration of tasks cannot be known *a priori*. As an example, tasks could be queued at a daemon behind a long-running task, whilst other daemons are idle having already completed their tasks.
243243

@@ -263,14 +263,14 @@ By super-assignment, the conenction 'con' will be available in the global enviro
263263
``` r
264264
m <- mirai(capture.output(str(con)))
265265
m[]
266-
#> [1] "Formal class 'SQLiteConnection' [package \"RSQLite\"] with 8 slots"
267-
#> [2] " ..@ ptr :<externalptr> "
268-
#> [3] " ..@ dbname : chr \"/tmp/RtmpNpLurX/file41de62846484\""
269-
#> [4] " ..@ loadable.extensions: logi TRUE"
270-
#> [5] " ..@ flags : int 70"
271-
#> [6] " ..@ vfs : chr \"\""
272-
#> [7] " ..@ ref :<environment: 0x5c6aa4117290> "
273-
#> [8] " ..@ bigint : chr \"integer64\""
266+
#> [1] "Formal class 'SQLiteConnection' [package \"RSQLite\"] with 8 slots"
267+
#> [2] " ..@ ptr :<externalptr> "
268+
#> [3] " ..@ dbname : chr \"/tmp/RtmpEHceL3/file2f4e14cc04969\""
269+
#> [4] " ..@ loadable.extensions: logi TRUE"
270+
#> [5] " ..@ flags : int 70"
271+
#> [6] " ..@ vfs : chr \"\""
272+
#> [7] " ..@ ref :<environment: 0x5916aca439e8> "
273+
#> [8] " ..@ bigint : chr \"integer64\""
274274
#> [9] " ..@ extended_types : logi FALSE"
275275
```
276276
Disconnect from the database everywhere, and set the number of daemons to zero to reset.
@@ -321,7 +321,7 @@ status()
321321
#> [1] 0
322322
#>
323323
#> $daemons
324-
#> [1] "tcp://hostname:40229"
324+
#> [1] "tcp://hostname:41463"
325325
#>
326326
#> $mirai
327327
#> awaiting executing completed
@@ -415,10 +415,10 @@ daemons(url = host_url())
415415
#> [1] 0
416416
launch_remote(2)
417417
#> [1]
418-
#> Rscript -e 'mirai::daemon("tcp://hostname:35271",rs=c(10407,-1530821818,1172745487,1569806340,-1495290059,-1405485454,-623998133),dispatcher=TRUE)'
418+
#> Rscript -e 'mirai::daemon("tcp://hostname:41983",rs=c(10407,-1344689176,-1963888439,-153451018,1270924287,927983156,1071643557),dispatcher=TRUE)'
419419
#>
420420
#> [2]
421-
#> Rscript -e 'mirai::daemon("tcp://hostname:35271",rs=c(10407,-1530368338,1487510998,410552886,341922669,-1519351038,713262429),dispatcher=TRUE)'
421+
#> Rscript -e 'mirai::daemon("tcp://hostname:41983",rs=c(10407,615178451,635795015,145221564,-251292842,-5310680,-284738001),dispatcher=TRUE)'
422422
daemons(0)
423423
#> [1] 0
424424
```
@@ -445,37 +445,37 @@ The generated self-signed certificate is available via `launch_remote()`. This f
445445
``` r
446446
launch_remote(1)
447447
#> [1]
448-
#> Rscript -e 'mirai::daemon("tls+tcp://hostname:46211",tls=c("-----BEGIN CERTIFICATE-----
448+
#> Rscript -e 'mirai::daemon("tls+tcp://hostname:39557",tls=c("-----BEGIN CERTIFICATE-----
449449
#> MIIFNzCCAx+gAwIBAgIBATANBgkqhkiG9w0BAQsFADAzMREwDwYDVQQDDAhrdW1h
450450
#> bW90bzERMA8GA1UECgwITmFub25leHQxCzAJBgNVBAYTAkpQMB4XDTAxMDEwMTAw
451451
#> MDAwMFoXDTMwMTIzMTIzNTk1OVowMzERMA8GA1UEAwwIa3VtYW1vdG8xETAPBgNV
452452
#> BAoMCE5hbm9uZXh0MQswCQYDVQQGEwJKUDCCAiIwDQYJKoZIhvcNAQEBBQADggIP
453-
#> ADCCAgoCggIBAMHvURMO9cT0Y0CSaE4e2fZeu8/uTTa6DTIzp3KXhPDPxDLRbubz
454-
#> Ya0aZ2LbWxcAAgAtgO1Sr/0XOp3NG+b7OvMijBYaZASFidc+Nw4exsXpw5nYWf4W
455-
#> rAr1a008X1dSbH4Y0lwjSMRBrkD1gGhC5E9P+U8UOrpemeT0NjdcmKEaxrWbTpPy
456-
#> adNzsHCgDo7615N4s2ppZ67abZr/jYAbAz8t2mwzJztfP9vOsB5kSKR3Gw8ge9wd
457-
#> DecS6O31EuoAV4vm2mQLfV77AOz1JXj9UHsgckC3fvU7lYFTfewrMXxEfSfwB6Ac
458-
#> /KZRrcr90nGZ7HwoHJPuHvrMWInWAazXrws+8bcoyyOx6mvfuNseDoVLKImX0Vka
459-
#> lLoUxhDOnfeD2sTLeWVPIwL9lwjbKRzE+fquv8R9Z2IVM8UWG/C47WTxRfPPmZFy
460-
#> x8PEq5bPTTQKrerbcn5lYEjYKaYYVH22m/SFh2frAp9QQCjCIyCjxpmcASMKQ8j4
461-
#> YVZtHK3znsmI4+L3MQG/OK0h9kGwGqm8ZvUfbZl0zk6ADbF0XhwSN3Mld9zUiRUY
462-
#> JcNH6y6+6PJ5r+sxASlEA3GNKEL9HPslbqKRiTW3Flf4GAIQHHjQvFFsn+wBm+az
463-
#> yBL96rtTxiozsLkUCaAGdnjWvkVtYy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xIGe+
470+
#> rsnY/NvTTwF491a4kVEGQqT/9BBJ47GAoA8TGvaG88Spu+ZeMh0hybr0v5Z869Em
471+
#> LQFvziB7Jr3cQtvxwUKP3EnPB+FCGEQ2N1vcW6H098kN1uOVhi2lyox0cxy69RDl
472+
#> XKJWfVw1YDc2TUk2KyMAkcC2DEqW0YLjog603XilifeI07viJAI8D1BMBioOF2ub
473+
#> H5YVqTtzueok5PFL6gKU/FxJChfFHS+vMEksUmhA/gbnE2gmARXWUp1YRENmaOlq
474+
#> jGEjSVUSWJmz/Yxirdw8V+F/5Im0Rw9x2qi8Rcz4NpFLXZAE96XEfiBnSE+igcx/
475+
#> va1vKQYG8+QlnaOj/tWcm7Ds2qyDXM2tkRg/wY5wn8zzbQIu1kaMaQQtQyRkm0Qb
476+
#> eD0ANbWVm6sme3OcOIXOKWQ6SHsVfUxTu1oQxP0db0ub77YrwnQAyUm7cA==
477477
#> -----END CERTIFICATE-----
478-
#> ",""),rs=c(10407,-72214235,-1307966558,399909563,418926272,-375992383,-2045629810),dispatcher=TRUE)'
478+
#> ",""),rs=c(10407,170097720,1743868121,-835599674,1736640143,-1848605820,-567606091),dispatcher=TRUE)'
479479
```
480480
The printed value may be deployed directly on a remote machine.
481481

@@ -555,10 +555,10 @@ m3[]
555555

556556
m3$data$stack.trace
557557
#> [[1]]
558-
#> [1] "stop(\"positive\")"
558+
#> stop("positive")
559559
#>
560560
#> [[2]]
561-
#> [1] "f(1)"
561+
#> f(1)
562562
```
563563
Elements of the original error condition are also accessible via `$` on the error object. For example, additional metadata recorded by `rlang::abort()` is preserved:
564564

@@ -726,10 +726,10 @@ daemons(4)
726726
vec <- c(1, 1, 4, 4, 1, 1, 1, 1)
727727
system.time(mirai_map(vec, Sys.sleep)[])
728728
#> user system elapsed
729-
#> 0.007 0.002 4.008
729+
#> 0.004 0.003 4.007
730730
system.time(parLapply(cl, vec, Sys.sleep))
731731
#> user system elapsed
732-
#> 0.013 0.000 8.012
732+
#> 0.011 0.006 8.012
733733
daemons(0)
734734
#> [1] 0
735735
```
@@ -741,13 +741,13 @@ with(
741741
mirai_map(1:3, rnorm, .args = list(mean = 20, sd = 2))[]
742742
)
743743
#> [[1]]
744-
#> [1] 20.70451
744+
#> [1] 21.84541
745745
#>
746746
#> [[2]]
747-
#> [1] 20.35063 19.32122
747+
#> [1] 18.23470 20.94375
748748
#>
749749
#> [[3]]
750-
#> [1] 20.96368 22.46151 19.95492
750+
#> [1] 18.39093 16.46124 20.26067
751751
```
752752
Use `...` to further specify objects referenced but not defined in `.f` - the 'do' in the anonymous function below:
753753

@@ -760,16 +760,16 @@ ml <- mirai_map(
760760
do = nanonext::random
761761
)
762762
ml
763-
#> < mirai map [2/3] >
763+
#> < mirai map [0/3] >
764764
ml[]
765765
#> $a
766-
#> [1] "51"
766+
#> [1] "53"
767767
#>
768768
#> $b
769-
#> [1] 33 89
769+
#> [1] f1 05
770770
#>
771771
#> $c
772-
#> [1] "a06c24"
772+
#> [1] "3cb8d3"
773773
```
774774
Use of `mirai_map()` requires that `daemons()` have previously been set, and will error if not.
775775

0 commit comments

Comments
 (0)