Skip to content

Commit

Permalink
Better error message for missing search field
Browse files Browse the repository at this point in the history
* previously would have given
```
Error in if (fieldtype == "STRING") { : argument is of length zero
```
  • Loading branch information
jefferis committed Jul 25, 2024
1 parent 5ca4f7b commit 93c7f45
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions R/name.R
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,10 @@ neuprint_search <- function(search, field = "name", fixed=FALSE, exact=NULL,
where=search
} else {
fieldtype=neuprint_typeof(field, type = 'neo4j', conn=conn, dataset = dataset)
if(length(fieldtype)==0) {
stop("Sorry, the `", field,
"` field doesn't exist in neuprint database (which is case-sensitive)!")
}
if(fieldtype=="STRING") {
search=glue('\\"{search}\\"')
operator=ifelse(fixed, ifelse(exact, "=", "CONTAINS"), "=~")
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-ids.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,6 @@ test_that("neuprint_ids works", {
expect_true(all(neuprint_ids("!MBON01") %in% mbons))
expect_equal(neuprint_ids("/MBON[0-9]+"),
as.character(neuprint_search("type:MBON[0-9]+", meta=FALSE)))

expect_error(neuprint_ids('rhubarb:.+'), "rhubarb.*doesn't.*exist")
})

0 comments on commit 93c7f45

Please sign in to comment.