DDorch / Rthingsboard

R package for interacting with the API of ThingsBoard open-source IoT platform.
GNU Affero General Public License v3.0
3 stars 0 forks source link

CRAN check run examples failed because of unavailability of the Thingsboard server #4

Closed DDorch closed 3 years ago

DDorch commented 3 years ago

Kurt Hornik wrote:

Dear maintainer, Please see the problems shown on https://cran.r-project.org/web/checks/check_results_Rthingsboard.html. Please correct before 2021-02-02 to safely retain your package on CRAN. Best, -k

For the record: we're seeing things like

> ### Name: ThingsboardApi-class
> ### Title: Thingboard API Class
> ### Aliases: ThingsboardApi-class ThingsboardApi
>
> ### ** Examples
>
> thinksboard_api = ThingsboardApi(url="http://scada.g-eau.net",
+ publicId="299cedc0-f3e9-11e8-9dbf-cbc1e37c11e3")
======== End of example output (where/before crash/hang up occured ?) ========

You should really set a reasonable web access timeout, and handle web access problems gracefully.

DDorch commented 3 years ago

On Monday the server was down and there was an fatal error from curl.

I'm not sure how to define "Handle web access problems gracefully". Currently, any operation that fails throw an error. For example:

library(Rthingsboard)
url = "http://scada.g-eau.fr"
publicId = "299cedc0-f3e9-11e8-9dbf-cbc1e37c11e3"
tb_api = ThingsboardApi(url = url, publicId = publicId)
publicId = "299cedc0-f3e9-11e8-9dbf-cbc1e37c11e4"
tb_api = ThingsboardApi(url = url, publicId = publicId)
Error in getToken() : 
  Request failed with status Client error: (401) Unauthorized
url = "http://toto.zzz.fr"
tb_api = ThingsboardApi(url = url, publicId = publicId)
Error in getToken() : 
  Request failed with status Client error: (404) Not Found

These messages seem appropriate and comprehensible for me because they are the same errors sent by the API.

Referring to https://bookdown.org/rdpeng/RProgDA/error-handling-and-generation.html, "Stopping the execution of your program with stop() should only happen in the event of a catastrophe - meaning only if it is impossible for your program to continue."

In all the errors above, the error is fatal for the followings procedures to run, so the program must be stopped. So I don't think that gracefully catch these errors in order to throw a warning and return a special value like FALSE is a good idea.

The user should handle these errors with a tryCatch, so I would change the example in this way.

DDorch commented 3 years ago

I also tested the case of a non responding server which was the case that happened on Monday:

url = "https://data-preproduction.inrae.fr"
tb_api = ThingsboardApi(url = url, publicId = publicId)
Error in curl::curl_fetch_memory(url, handle = handle) : 
  Timeout was reached: [data-preproduction.inrae.fr] Connection timed out after 10014 milliseconds

But I have done a check with this example and I get:

v  checking examples (11.1s)
   Examples with CPU (user + system) or elapsed time > 5s
                        user system elapsed
   ThingsboardApi-class 0.11   0.01    10.1

So this example can't stay in the check if ever the server is not available during check.