## Addapted from '~/git/orch/src/Spotify Playlist Webscrape/get_playlist_data.r'

test_example <- function(playlists.uri, fill=FALSE, verbose=TRUE) {

  lapply(playlists.uri, function(uri) {
    verboseMsg(verbose, "\t---- PROCESSING ", uri, " ----", func="message", minw=-20)
    # try(get_playlist_data(uri=uri, token=token, jesus=TRUE, verbose.processing=FALSE, verbose=verbose), silent=FALSE)
    if (!isTRUE(uri == 2))
      as.data.table(rbind(setNames(sample(LETTERS, 3), obj=1:3)))
  }) %>% {
    ## this next pipe should just be rbindlist; 
    ## however, in the event that the rbindlist fails, we don't want to have wasted all of that effort parsing and processing. 
    ## So we wrap the error and return the list un flattened
    tryCatch(rbindlist(., fill=fill, use.names=TRUE), error=function(e) {warning("Internal error when trying to rbindlist in process_list_of_playlists()\nWill return the list as-is\n\nOriginal Error:\n", e$msg, call.=FALSE); return(.)})
  }
}

if (FALSE) {
  test_example(1:3, fill=FALSE)
  test_example(1:3, fill=TRUE)
}

