Skip to content

Commit a90683e

Browse files
committed
chore: replace last calls to stop()
Except for tkplot that we will remove. Fixes #731
1 parent 9ddc43e commit a90683e

4 files changed

Lines changed: 15 additions & 9 deletions

File tree

R/console.R

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ console <- function() {
8686
type,
8787
"tk" = .igraph.progress.tk(percent, message),
8888
"tkconsole" = .igraph.progress.tkconsole(percent, message),
89-
stop("Cannot interpret 'verbose' option, this should not happen")
89+
cli::cli_abort(
90+
"Unknown value for the {.arg verbose} option.",
91+
.internal = TRUE
92+
)
9093
)
9194
}
9295
}
@@ -103,7 +106,10 @@ console <- function() {
103106
type,
104107
"tk" = message(message, appendLF = FALSE),
105108
"tkconsole" = .igraph.progress.tkconsole.message(message, start = TRUE),
106-
stop("Cannot interpret 'verbose' option, this should not happen")
109+
cli::cli_abort(
110+
"Unknown value for the {.arg verbose} option.",
111+
.internal = TRUE
112+
)
107113
)
108114
}
109115
0L

R/interface.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ add_edges <- function(graph, edges, ..., attr = list()) {
146146
attrs <- append(attrs, attr)
147147
nam <- names(attrs)
148148
if (length(attrs) != 0 && (is.null(nam) || any(nam == ""))) {
149-
stop("please supply names for attributes")
149+
cli::cli_abort("All attributes must be named.")
150150
}
151151

152152
edges.orig <- ecount(graph)
@@ -213,7 +213,7 @@ add_vertices <- function(graph, nv, ..., attr = list()) {
213213
attrs <- append(attrs, attr)
214214
nam <- names(attrs)
215215
if (length(attrs) != 0 && (is.null(nam) || any(nam == ""))) {
216-
stop("please supply names for attributes")
216+
cli::cli_abort("All attributes must be named.")
217217
}
218218

219219
vertices.orig <- vcount(graph)
@@ -354,7 +354,7 @@ neighbors <- function(graph, v, mode = c("out", "in", "all", "total")) {
354354

355355
v <- as_igraph_vs(graph, v)
356356
if (length(v) == 0) {
357-
stop("No vertex was specified")
357+
cli::cli_abort("{.arg v} must specify at least one vertex.")
358358
}
359359

360360
neighbors_impl(

R/iterators.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,7 +1151,7 @@ simple_es_index <- function(x, i, na_ok = FALSE) {
11511151
cli::cli_abort("Invalid indexing.")
11521152
}
11531153
if (is.null(get_vs_graph(x))) {
1154-
stop("Graph is unknown.")
1154+
cli::cli_abort("Graph is unknown.", .internal = TRUE)
11551155
}
11561156
value
11571157
}
@@ -1170,10 +1170,10 @@ simple_es_index <- function(x, i, na_ok = FALSE) {
11701170
!"name" %in% names(attributes(value)) ||
11711171
!"value" %in% names(attributes(value))
11721172
) {
1173-
stop("Invalid indexing.")
1173+
cli::cli_abort("Invalid indexing.")
11741174
}
11751175
if (is.null(get_es_graph(x))) {
1176-
stop("Graph is unknown.")
1176+
cli::cli_abort("Graph is unknown.", .internal = TRUE)
11771177
}
11781178
value
11791179
}

tests/testthat/test-interface.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ test_that("neighbors works", {
9999

100100
test_that("neighbors prints an error for an empty input vector", {
101101
g <- make_tree(10)
102-
expect_error(neighbors(g, numeric()), "No vertex was specified")
102+
expect_error(neighbors(g, numeric()), "at least one vertex")
103103
})
104104

105105

0 commit comments

Comments
 (0)