RLesur / crrri

A Chrome Remote Interface written in R
https://rlesur.github.io/crrri/
Other
157 stars 12 forks source link

Debugme log in double sometimes #14

Open cderv opened 5 years ago

cderv commented 5 years ago

Following #10, there seems to be an issue with how !DEBUG line are called.

> chrome <- chr_connect() 
crrri Trying to launch Chrome  
crrri Trying to launch Chrome in headless mode ... +2ms 
Running "C:/Users/chris/Documents/Chrome/chrome-win32/chrome.exe" \
  --no-first-run --headless "--user-data-dir=chrome-data-dir-jtfwycqz" \
  "--remote-debugging-port=9222" --disable-gpu --no-sandbox
crrri +-Chrome succesfully launched  +15ms 
crrri Chrome succesfully launched in headless mode. +1ms 
crrri +-It should be accessible at http://localhost: +0ms 
crrri It should be accessible at http://localhost:9222 +1ms 
crrri Trying to find  +1ms 
crrri Trying to find http://localhost:9222 +1ms 
crrri +-attempt  +0ms 
crrri attempt 1... +1ms 
crrri +- +310ms 
crrri ... http://localhost:9222 found +1ms 
crrri Retrieving Chrome websocket entrypoint at http://localhost: +1ms 
crrri Retrieving Chrome websocket entrypoint at http://localhost:9222/json ... +1ms 
crrri +-...found websocket entrypoint  +1387ms 
crrri ...found websocket entrypoint ws://localhost:9222/devtools/page/AB2AC45BB31BB240C8B28DCF725F331B +1ms 
crrri Configuring the websocket connexion... +1ms 
crrri Configuring the websocket connexion... +1ms 
crrri +-...websocket connexion configured. +6ms 
crrri ...websocket connexion configured. +0ms 
crrri Connecting R to Chrome... +4ms 
crrri Connecting R to Chrome... +0ms 
crrri ...R succesfully connected to headless Chrome through DevTools Protocol. +1110ms 
crrri ...R succesfully connected to headless Chrome through DevTools Protocol. +1ms 

some messages are duplicated and I don't know why... Some are printed before the value in backtick is evaluated. It is not really important regarding how the 📦 works but an improvement to look into on the long run. And see if it happens to other people too...

There are other solution to this if debugme as an issue...

RLesur commented 5 years ago

I wonder whether it could be linked to lazy eval

cderv commented 5 years ago

After some searching time, I find that the "!DEBUG " line are replace by two calls to debugme::debug(). Exemple from https://github.com/RLesur/crrri/blob/de6fd8e9f0402bc0d57e8f46b5872fddf7a5d47b/R/chr_connect.R#L227 gets transform in

debugme::debug(paste0(debugme::debug("!DEBUG Trying to find "), 
        url))

Will look into debugme - I may have understand it wrong...

cderv commented 5 years ago

This is a debugme issue.

It happens with :

First debug process transforms the string correctly : "!DEBUG x= x" to debugme::debugme(paste0("!DEBUG x=", x)). This is inserted in the function in place of debug string. However if the function is called again, "!DEBUG x=" is catched again (the one in paste0) and replace with a debugme call.

We have to improve debugme or change to our own internals messaging function. Maybe with cli and several levels to print some message to users and others to developers.

cderv commented 5 years ago

Can't reproduce on a dummy 📦 . only happens with crrri. I put this on hold for now.

RLesur commented 5 years ago

My guess is it could be related to the use inside promises::promise(). I don't have tested so far.

cderv commented 5 years ago

Another hint: Here is how the code is transformed after loading the package (this is when DEBUGME is parsed and transformed)

function (host = "localhost", port = 9222, secure = FALSE) 
{
  debugme::debug(paste0(debugme::debug(debugme::debug(debugme::debug(debugme::debug(debugme::debug(debugme::debug(debugme::debug(debugme::debug("!DEBUG Retrieving Chrome websocket entrypoint at http://localhost:")))))))), 
    port, "/json ..."))
  targets <- list_targets(host, port, secure)
  active_target <- purrr::detect(targets, ~identical(.x$type, 
    "page"))
  address <- active_target$webSocketDebuggerUrl
  if (is.null(address)) 
    debugme::debug(debugme::debug(debugme::debug(debugme::debug(debugme::debug(debugme::debug(debugme::debug(debugme::debug(debugme::debug("!DEBUG ...websocket entrypoint unavailable.")))))))))
  else debugme::debug(paste0(debugme::debug(debugme::debug(debugme::debug(debugme::debug(debugme::debug(debugme::debug(debugme::debug(debugme::debug("!DEBUG ...found websocket entrypoint ")))))))), 
    address))
  if (isTRUE(secure)) {
    address <- httr::modify_url(address, scheme = "wss")
  }
  address
}

Way too many debugme::debug() ! There is definitely something off with how debugme is doing on our package