Skip to content

Commit e78fb8a

Browse files
committed
trace call on all errors and warnings
1 parent 0026477 commit e78fb8a

File tree

9 files changed

+31
-30
lines changed

9 files changed

+31
-30
lines changed

NEWS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
* New `stream()` interface exposes low-level byte stream functionality in the NNG library, intended for communicating with non-NNG endpoints, including but not limited to websocket servers.
66
* `ncurl()` adds an 'async' option to perform HTTP requests asynchronously, returning immediately with a 'recvAio'. Also adds explicit arguments for HTTP method, headers (which takes a named list or character vector) and request data.
7-
* New `messenger()` function implements a console-based 2-way messaging system using NNG's scalability protocols [currently experimental and undergoing testing].
7+
* New `messenger()` function implements a multi-threaded console-based messaging system using NNG's scalability protocols.
88

99
#### Updates
1010

1111
* Unified `send()` and `recv()` functions, and their asynchronous counterparts `send_aio()` and `recv_aio()`, are now S3 generics and can be used across Sockets, Contexts and Streams.
1212
* Revised 'block' argument for `send()` and `recv()` now allows an integer value for setting a timeout.
1313
* `send_ctx()` and `recv_ctx()` are deprecated and will be removed in a future package version - the methods for `send()` and `recv()` should be used instead.
14-
* Returned NNG error codes are now all classed 'errorValue' and messages have been upgraded to warnings across the package.
14+
* Returned NNG error codes are now all classed 'errorValue' and messages have been upgraded to warnings across the package to allow enhanced reporting of the originating call e.g. via `warnings()`. Timestamps have been removed in a trade-off for better performance.
1515
* Logging is deprecated and in the process of being phased out. Logging can still be set via 'NANONEXT_LOG' prior to package load but `logging()` can no longer be used. Logging will be removed entirely in a future package version.
1616

1717
# nanonext 0.3.0

R/messenger.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
#' Messenger
44
#'
5-
#' Console-based 2-way messaging system based on NNG scalability protocols.
5+
#' Multi-threaded console-based 2-way messaging system based on NNG scalability
6+
#' protocols.
67
#'
78
#' @param url a URL to connect to, specifying the transport and address as
89
#' a character string e.g. 'tcp://127.0.0.1:5555' (see \link{transports}).

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ aio
370370
#> < recvAio >
371371
#> - $data for message data
372372
aio$data |> str()
373-
#> num [1:100000000] 1.0489 0.7951 -0.5668 -0.1798 0.0081 ...
373+
#> num [1:100000000] -0.17 -0.573 1.068 0.363 -0.864 ...
374374
```
375375

376376
As `call_aio()` is blocking and will wait for completion, an alternative
@@ -407,7 +407,8 @@ sub |> recv(mode = "character", keep.raw = FALSE)
407407

408408
pub |> send(c("other", "this other topic will not be received"), mode = "raw", echo = FALSE)
409409
sub |> recv(mode = "character", keep.raw = FALSE)
410-
#> Warning: [ 8 ] Try again
410+
#> Warning in recv.nanoSocket(sub, mode = "character", keep.raw = FALSE): [ 8 ] Try
411+
#> again
411412

412413
# specify NULL to subscribe to ALL topics
413414
sub |> subscribe(topic = NULL)
@@ -418,7 +419,7 @@ sub |> recv("character", keep.raw = FALSE)
418419
sub |> unsubscribe(topic = NULL)
419420
pub |> send(c("newTopic", "this topic will now not be received"), mode = "raw", echo = FALSE)
420421
sub |> recv("character", keep.raw = FALSE)
421-
#> Warning: [ 8 ] Try again
422+
#> Warning in recv.nanoSocket(sub, "character", keep.raw = FALSE): [ 8 ] Try again
422423

423424
# however the topics explicitly subscribed to are still received
424425
pub |> send(c("examples", "this example will still be received"), mode = "raw", echo = FALSE)
@@ -474,7 +475,7 @@ aio2$data
474475
# after the survey expires, the second resolves into a timeout error
475476
Sys.sleep(0.5)
476477
aio2$data
477-
#> Warning: [ 5 ] Timed out
478+
#> Warning in (function (x) : [ 5 ] Timed out
478479
#> 'errorValue' int 5
479480

480481
close(sur)
@@ -504,11 +505,11 @@ ncurl("http://httpbin.org/headers")
504505
#> [1] 7b 0a 20 20 22 68 65 61 64 65 72 73 22 3a 20 7b 0a 20 20 20 20 22 48 6f 73
505506
#> [26] 74 22 3a 20 22 68 74 74 70 62 69 6e 2e 6f 72 67 22 2c 20 0a 20 20 20 20 22
506507
#> [51] 58 2d 41 6d 7a 6e 2d 54 72 61 63 65 2d 49 64 22 3a 20 22 52 6f 6f 74 3d 31
507-
#> [76] 2d 36 32 34 63 39 66 31 32 2d 32 64 31 31 65 38 35 62 32 32 61 34 65 36 36
508-
#> [101] 66 31 38 63 62 32 66 31 36 22 0a 20 20 7d 0a 7d 0a
508+
#> [76] 2d 36 32 34 63 62 66 66 38 2d 34 38 37 35 38 64 65 30 31 36 61 62 38 31 62
509+
#> [101] 34 36 38 39 31 32 66 37 61 22 0a 20 20 7d 0a 7d 0a
509510
#>
510511
#> $data
511-
#> [1] "{\n \"headers\": {\n \"Host\": \"httpbin.org\", \n \"X-Amzn-Trace-Id\": \"Root=1-624c9f12-2d11e85b22a4e66f18cb2f16\"\n }\n}\n"
512+
#> [1] "{\n \"headers\": {\n \"Host\": \"httpbin.org\", \n \"X-Amzn-Trace-Id\": \"Root=1-624cbff8-48758de016ab81b468912f7a\"\n }\n}\n"
512513
```
513514

514515
For advanced use, supports additional HTTP methods such as POST or PUT.
@@ -523,7 +524,7 @@ res
523524
#> - $raw for raw message
524525

525526
call_aio(res)$data
526-
#> [1] "{\n \"args\": {}, \n \"data\": \"{\\\"key\\\": \\\"value\\\"}\", \n \"files\": {}, \n \"form\": {}, \n \"headers\": {\n \"Authorization\": \"Bearer APIKEY\", \n \"Content-Length\": \"16\", \n \"Content-Type\": \"application/json\", \n \"Host\": \"httpbin.org\", \n \"X-Amzn-Trace-Id\": \"Root=1-624c9f12-73d4984b4f201f7c28549806\"\n }, \n \"json\": {\n \"key\": \"value\"\n }, \n \"origin\": \"78.145.225.121\", \n \"url\": \"http://httpbin.org/post\"\n}\n"
527+
#> [1] "{\n \"args\": {}, \n \"data\": \"{\\\"key\\\": \\\"value\\\"}\", \n \"files\": {}, \n \"form\": {}, \n \"headers\": {\n \"Authorization\": \"Bearer APIKEY\", \n \"Content-Length\": \"16\", \n \"Content-Type\": \"application/json\", \n \"Host\": \"httpbin.org\", \n \"X-Amzn-Trace-Id\": \"Root=1-624cbff8-6717d2692cf3ae776109d3c9\"\n }, \n \"json\": {\n \"key\": \"value\"\n }, \n \"origin\": \"79.173.189.204\", \n \"url\": \"http://httpbin.org/post\"\n}\n"
527528
```
528529

529530
In this respect, it may be used as a performant and lightweight method

man/messenger.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.

src/aio.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static SEXP mk_error(const int xc) {
3737

3838
SEXP err = PROTECT(Rf_ScalarInteger(xc));
3939
Rf_classgets(err, Rf_mkString("errorValue"));
40-
Rf_warningcall(R_NilValue, "[ %d ] %s", xc, nng_strerror(xc));
40+
Rf_warning("[ %d ] %s", xc, nng_strerror(xc));
4141
UNPROTECT(1);
4242
return err;
4343

@@ -445,9 +445,9 @@ SEXP rnng_stream_send_aio(SEXP stream, SEXP data, SEXP timeout) {
445445
SEXP rnng_aio_result(SEXP aio) {
446446

447447
if (R_ExternalPtrTag(aio) != nano_AioSymbol)
448-
error_return("'aio' is not a valid Aio");
448+
error_return("object is not a valid Aio");
449449
if (R_ExternalPtrAddr(aio) == NULL)
450-
error_return("'aio' is not an active Aio");
450+
error_return("object is not an active Aio");
451451

452452
uint8_t resolv;
453453
nano_aio *aiop = (nano_aio *) R_ExternalPtrAddr(aio);
@@ -469,9 +469,9 @@ SEXP rnng_aio_result(SEXP aio) {
469469
SEXP rnng_aio_get_msg(SEXP aio) {
470470

471471
if (R_ExternalPtrTag(aio) != nano_AioSymbol)
472-
error_return("'aio' is not a valid Aio");
472+
error_return("object is not a valid Aio");
473473
if (R_ExternalPtrAddr(aio) == NULL)
474-
error_return("'aio' is not an active Aio");
474+
error_return("object is not an active Aio");
475475

476476
uint8_t resolv;
477477
nano_aio *raio = (nano_aio *) R_ExternalPtrAddr(aio);
@@ -499,9 +499,9 @@ SEXP rnng_aio_get_msg(SEXP aio) {
499499
SEXP rnng_aio_stream_in(SEXP aio) {
500500

501501
if (R_ExternalPtrTag(aio) != nano_AioSymbol)
502-
error_return("'aio' is not a valid Aio");
502+
error_return("object is not a valid Aio");
503503
if (R_ExternalPtrAddr(aio) == NULL)
504-
error_return("'aio' is not an active Aio");
504+
error_return("object is not an active Aio");
505505

506506
uint8_t resolv;
507507
nano_aio *iaio = (nano_aio *) R_ExternalPtrAddr(aio);
@@ -550,13 +550,11 @@ SEXP rnng_aio_call(SEXP aio) {
550550
SEXP rnng_aio_stop(SEXP aio) {
551551

552552
if (TYPEOF(aio) != ENVSXP)
553-
error_return("'aio' is not a valid Aio");
553+
error_return("object is not an active Aio");
554554

555555
SEXP coreaio = Rf_findVarInFrame(aio, nano_AioSymbol);
556-
if (R_ExternalPtrTag(coreaio) != nano_AioSymbol)
557-
error_return("'aio' is not a valid Aio");
558-
if (R_ExternalPtrAddr(coreaio) == NULL)
559-
error_return("'aio' is not an active Aio");
556+
if (R_ExternalPtrTag(coreaio) != nano_AioSymbol || R_ExternalPtrAddr(coreaio) == NULL)
557+
error_return("object is not an active Aio");
560558

561559
nano_aio *aiop = (nano_aio *) R_ExternalPtrAddr(coreaio);
562560
nng_aio_stop(aiop->aio);
@@ -788,9 +786,9 @@ SEXP rnng_ncurl_aio(SEXP http, SEXP method, SEXP headers, SEXP data) {
788786
SEXP rnng_aio_http(SEXP aio) {
789787

790788
if (R_ExternalPtrTag(aio) != nano_AioSymbol)
791-
error_return("'aio' is not a valid Aio");
789+
errorcall_return(R_NilValue, "object is not a valid Aio");
792790
if (R_ExternalPtrAddr(aio) == NULL)
793-
error_return("'aio' is not an active Aio");
791+
errorcall_return(R_NilValue, "object is not an active Aio");
794792

795793
uint8_t resolv;
796794
nano_aio *haio = (nano_aio *) R_ExternalPtrAddr(aio);

src/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ static SEXP mk_error(const int xc) {
99

1010
SEXP err = PROTECT(Rf_ScalarInteger(xc));
1111
Rf_classgets(err, Rf_mkString("errorValue"));
12-
Rf_warningcall(R_NilValue, "[ %d ] %s", xc, nng_strerror(xc));
12+
Rf_warning("[ %d ] %s", xc, nng_strerror(xc));
1313
UNPROTECT(1);
1414
return err;
1515

src/opts.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ static SEXP mk_error(const int xc) {
99

1010
SEXP err = PROTECT(Rf_ScalarInteger(xc));
1111
Rf_classgets(err, Rf_mkString("errorValue"));
12-
Rf_warningcall(R_NilValue, "[ %d ] %s", xc, nng_strerror(xc));
12+
Rf_warning("[ %d ] %s", xc, nng_strerror(xc));
1313
UNPROTECT(1);
1414
return err;
1515

src/sockets.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static SEXP mk_error(const int xc) {
2121

2222
SEXP err = PROTECT(Rf_ScalarInteger(xc));
2323
Rf_classgets(err, Rf_mkString("errorValue"));
24-
Rf_warningcall(R_NilValue, "[ %d ] %s", xc, nng_strerror(xc));
24+
Rf_warning("[ %d ] %s", xc, nng_strerror(xc));
2525
UNPROTECT(1);
2626
return err;
2727

src/utils.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ static SEXP mk_error(const int xc) {
1111

1212
SEXP err = PROTECT(Rf_ScalarInteger(xc));
1313
Rf_classgets(err, Rf_mkString("errorValue"));
14-
Rf_warningcall(R_NilValue, "[ %d ] %s", xc, nng_strerror(xc));
14+
Rf_warning("[ %d ] %s", xc, nng_strerror(xc));
1515
UNPROTECT(1);
1616
return err;
1717

0 commit comments

Comments
 (0)