Skip to content

Commit

Permalink
fix: changing all error messages and warnings to use cli_alert_*()
Browse files Browse the repository at this point in the history
…functions
  • Loading branch information
saiemgilani committed Jul 21, 2024
1 parent d5e9a49 commit 8c67f70
Show file tree
Hide file tree
Showing 23 changed files with 482 additions and 503 deletions.
113 changes: 50 additions & 63 deletions R/espn_wbb_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -220,20 +220,19 @@ espn_wbb_game_all <- function(game_id){
plays_df <- helper_espn_wbb_pbp(resp)

if (is.null(plays_df)) {
message(glue::glue("{Sys.time()}: No play-by-play data for {game_id} available!"))
cli::cli_alert_danger("{Sys.time()}: No play-by-play data for {game_id} available!")
}

},
error = function(e) {
message(
glue::glue(
cli::cli_alert_danger(
"{Sys.time()}: Invalid arguments or no play-by-play data for {game_id} available!"
)
)
message(glue::glue("Error:\n{e}"))

cli::cli_alert_danger("Error:\n{e}")
},
warning = function(w) {
message(glue::glue("{Sys.time()}: Warning:\n{w}"))
cli::cli_alert_warning("{Sys.time()}: Warning:\n{w}")
},
finally = {

Expand All @@ -246,20 +245,18 @@ espn_wbb_game_all <- function(game_id){
team_box_score <- helper_espn_wbb_team_box(resp)

if (is.null(team_box_score)) {
message(glue::glue("{Sys.time()}: No team box score data for {game_id} available!"))
cli::cli_alert_danger("{Sys.time()}: No team box score data for {game_id} available!")
}

},
error = function(e) {
message(
glue::glue(
cli::cli_alert_danger(
"{Sys.time()}: Invalid arguments or no team box score data for {game_id} available!"
)
)
message(glue::glue("Error:\n{e}"))
cli::cli_alert_danger("Error:\n{e}")
},
warning = function(w) {
message(glue::glue("{Sys.time()}: Warning:\n{w}"))
cli::cli_alert_warning("{Sys.time()}: Warning:\n{w}")
},
finally = {

Expand All @@ -272,20 +269,18 @@ espn_wbb_game_all <- function(game_id){
player_box_score <- helper_espn_wbb_player_box(resp)

if (is.null(player_box_score)) {
message(glue::glue("{Sys.time()}: No player box score data for {game_id} available!"))
cli::cli_alert_danger("{Sys.time()}: No player box score data for {game_id} available!")
}

},
error = function(e) {
message(
glue::glue(
cli::cli_alert_danger(
"{Sys.time()}: Invalid arguments or no player box score data for {game_id} available!"
)
)
message(glue::glue("Error:\n{e}"))
cli::cli_alert_danger("Error:\n{e}")
},
warning = function(w) {
message(glue::glue("{Sys.time()}: Warning:\n{w}"))
cli::cli_alert_warning("{Sys.time()}: Warning:\n{w}")
},
finally = {

Expand Down Expand Up @@ -397,20 +392,18 @@ espn_wbb_pbp <- function(game_id){
plays_df <- helper_espn_wbb_pbp(resp)

if (is.null(plays_df)) {
return(message(glue::glue("{Sys.time()}: No play-by-play data for {game_id} available!")))
return(cli::cli_alert_danger("{Sys.time()}: No play-by-play data for {game_id} available!"))
}

},
error = function(e) {
message(
glue::glue(
cli::cli_alert_danger(
"{Sys.time()}: Invalid arguments or no play-by-play data for {game_id} available!"
)
)
message(glue::glue("Error:\n{e}"))
cli::cli_alert_danger("Error:\n{e}")
},
warning = function(w) {
message(glue::glue("{Sys.time()}: Warning:\n{w}"))
cli::cli_alert_warning("{Sys.time()}: Warning:\n{w}")
},
finally = {

Expand Down Expand Up @@ -520,20 +513,18 @@ espn_wbb_team_box <- function(game_id){
team_box_score <- helper_espn_wbb_team_box(resp)

if (is.null(team_box_score)) {
return(message(glue::glue("{Sys.time()}: No team box score data for {game_id} available!")))
cli::cli_alert_danger("{Sys.time()}: No team box score data for {game_id} available!")
}

},
error = function(e) {
message(
glue::glue(
cli::cli_alert_danger(
"{Sys.time()}: Invalid arguments or no team box score data for {game_id} available!"
)
)
message(glue::glue("Error:\n{e}"))
cli::cli_alert_danger("Error:\n{e}")
},
warning = function(w) {
message(glue::glue("{Sys.time()}: Warning:\n{w}"))
cli::cli_alert_warning("{Sys.time()}: Warning:\n{w}")
},
finally = {

Expand Down Expand Up @@ -644,20 +635,18 @@ espn_wbb_player_box <- function(game_id){
player_box_score <- helper_espn_wbb_player_box(resp)

if (is.null(player_box_score)) {
return(message(glue::glue("{Sys.time()}: No player box score data for {game_id} available!")))
return(cli::cli_alert_danger("{Sys.time()}: No player box score data for {game_id} available!"))
}

},
error = function(e) {
message(
glue::glue(
cli::cli_alert_danger(
"{Sys.time()}: Invalid arguments or no player box score data for {game_id} available!"
)
)
message(glue::glue("Error:\n{e}"))
cli::cli_alert_danger("Error:\n{e}")
},
warning = function(w) {
message(glue::glue("{Sys.time()}: Warning:\n{w}"))
cli::cli_alert_warning("{Sys.time()}: Warning:\n{w}")
},
finally = {

Expand Down Expand Up @@ -963,15 +952,13 @@ espn_wbb_game_rosters <- function(game_id) {

},
error = function(e) {
message(
glue::glue(
cli::cli_alert_danger(
"{Sys.time()}: Invalid arguments or no game roster data for {game_id} available!"
)
)
message(glue::glue("Error:\n{e}"))
cli::cli_alert_danger("Error:\n{e}")
},
warning = function(w) {
message(glue::glue("{Sys.time()}: Warning:\n{w}"))
cli::cli_alert_warning("{Sys.time()}: Warning:\n{w}")
},
finally = {

Expand Down Expand Up @@ -1040,11 +1027,11 @@ espn_wbb_conferences <- function(){
make_wehoop_data("ESPN WBB Conferences Information from ESPN.com",Sys.time())
},
error = function(e) {
message(glue::glue("{Sys.time()}: Invalid arguments or no conferences info available!"))
message(glue::glue("Error:\n{e}"))
cli::cli_alert_danger("{Sys.time()}: Invalid arguments or no conferences info available!")
cli::cli_alert_danger("Error:\n{e}")
},
warning = function(w) {
message(glue::glue("{Sys.time()}: Warning:\n{w}"))
cli::cli_alert_warning("{Sys.time()}: Warning:\n{w}")
},
finally = {
}
Expand Down Expand Up @@ -1222,11 +1209,11 @@ espn_wbb_teams <- function(year = most_recent_wbb_season()){

},
error = function(e) {
message(glue::glue("{Sys.time()}: Invalid arguments or no teams data available!"))
message(glue::glue("Error:\n{e}"))
cli::cli_alert_danger("{Sys.time()}: Invalid arguments or no teams data available!")
cli::cli_alert_danger("Error:\n{e}")
},
warning = function(w) {
message(glue::glue("{Sys.time()}: Warning:\n{w}"))
cli::cli_alert_warning("{Sys.time()}: Warning:\n{w}")
},
finally = {
}
Expand Down Expand Up @@ -1445,10 +1432,10 @@ parse_espn_wbb_scoreboard <- function(group, season_dates) {

},
error = function(e) {
message(glue::glue("Error:\n{e}"))
cli::cli_alert_danger("Error:\n{e}")
},
warning = function(w) {
message(glue::glue("{Sys.time()}: Warning:\n{w}"))
cli::cli_alert_warning("{Sys.time()}: Warning:\n{w}")
},
finally = {

Expand Down Expand Up @@ -1537,9 +1524,9 @@ espn_wbb_scoreboard <- function(season) {
parse_espn_wbb_scoreboard)

if (!nrow(scoreboard_df)) {
message(glue::glue(
cli::cli_alert_danger(
"{Sys.time()}: Invalid arguments or no scoreboard data available!"
))
)
}
return(scoreboard_df)
}
Expand Down Expand Up @@ -1657,11 +1644,11 @@ espn_wbb_rankings <- function(){
make_wehoop_data("ESPN WBB Rankings Information from ESPN.com",Sys.time())
},
error = function(e) {
message(glue::glue("{Sys.time()}: Invalid arguments or no rankings data for {game_id} available!"))
message(glue::glue("Error:\n{e}"))
cli::cli_alert_danger("{Sys.time()}: Invalid arguments or no rankings data for {game_id} available!")
cli::cli_alert_danger("Error:\n{e}")
},
warning = function(w) {
message(glue::glue("{Sys.time()}: Warning:\n{w}"))
cli::cli_alert_warning("{Sys.time()}: Warning:\n{w}")
},
finally = {
}
Expand Down Expand Up @@ -1899,11 +1886,11 @@ espn_wbb_standings <- function(year){
make_wehoop_data("ESPN WBB Standings Information from ESPN.com",Sys.time())
},
error = function(e) {
message(glue::glue("{Sys.time()}: Invalid arguments or no standings data available!"))
message(glue::glue("Error:\n{e}"))
cli::cli_alert_danger("{Sys.time()}: Invalid arguments or no standings data available!")
cli::cli_alert_danger("Error:\n{e}")
},
warning = function(w) {
message(glue::glue("{Sys.time()}: Warning:\n{w}"))
cli::cli_alert_warning("{Sys.time()}: Warning:\n{w}")
},
finally = {
}
Expand Down Expand Up @@ -2149,11 +2136,11 @@ espn_wbb_team_stats <- function(

},
error = function(e) {
message(glue::glue("{Sys.time()}:Invalid arguments or no team season stats data available!"))
message(glue::glue("Error:\n{e}"))
cli::cli_alert_danger("{Sys.time()}:Invalid arguments or no team season stats data available!")
cli::cli_alert_danger("Error:\n{e}")
},
warning = function(w) {
message(glue::glue("{Sys.time()}: Warning:\n{w}"))
cli::cli_alert_warning("{Sys.time()}: Warning:\n{w}")
},
finally = {
}
Expand Down Expand Up @@ -2462,11 +2449,11 @@ espn_wbb_player_stats <- function(

},
error = function(e) {
message(glue::glue("{Sys.time()}:Invalid arguments or no player season stats data available!"))
message(glue::glue("Error:\n{e}"))
cli::cli_alert_danger("{Sys.time()}:Invalid arguments or no player season stats data available!")
cli::cli_alert_danger("Error:\n{e}")
},
warning = function(w) {
message(glue::glue("{Sys.time()}: Warning:\n{w}"))
cli::cli_alert_warning("{Sys.time()}: Warning:\n{w}")
},
finally = {
}
Expand Down
Loading

0 comments on commit 8c67f70

Please sign in to comment.