Skip to content

Commit

Permalink
Relax error to warning
Browse files Browse the repository at this point in the history
See #265
  • Loading branch information
peterdesmet committed Sep 13, 2024
1 parent 77c06ba commit b052cec
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 21 deletions.
5 changes: 3 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# frictionless (development version)

# frictionless 1.2.0

* `read_package()` now returns a warning rather than an error when a `datapackage.json` contains no resources. This allows use to create the JSON and then add resources with frictionless (#265).
* `example_package()` now has a `version` parameter, allowing to load the example Data Package following the Data Package [v1](https://specs.frictionlessdata.io/) or [v2](https://datapackage.org/) specification (#249).

# frictionless 1.2.0

## Changes for users

* `add_resource()` now allows to replace an existing resource (#227).
Expand Down
15 changes: 8 additions & 7 deletions R/read_package.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ read_package <- function(file = "datapackage.json") {
}
descriptor <- read_descriptor(file, safe = FALSE)

# Check resources are present
# Checking that they have a name is done when accessing, see check_package()
# https://specs.frictionlessdata.io/data-package/#metadata
# Warn if resources is absent
if (length(descriptor$resources) == 0) {
cli::cli_abort(
"{.arg file} {.file {file}} must have a {.field resources} property
containing at least one resource.",
class = "frictionless_error_file_without_resources"
cli::cli_warn(
c(
"{.arg file} {.file {file}} should have a {.field resources} property
containing at least one resource.",
"i" = "Use {.fun add_resource} to add resources."
),
class = "frictionless_warning_file_without_resources"
)
}

Expand Down
31 changes: 19 additions & 12 deletions tests/testthat/test-read_package.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ test_that("read_package() returns a valid Data Package reading from url", {
)
})

test_that("read_package() returns error on missing file and properties", {
test_that("read_package() returns error on missing or invalid file", {
skip_if_offline()
# Incorrect type
expect_error(
Expand Down Expand Up @@ -73,30 +73,37 @@ test_that("read_package() returns error on missing file and properties", {
fixed = FALSE
)

# No resources property
# No file remotely
expect_error(
read_package("https://example.com/nofile.json"),
class = "frictionless_error_url_not_found"
)
})

test_that("read_package() warns if resources are missing", {
# No resources property
expect_warning(
read_package(test_path("data/resources_missing.json")),
class = "frictionless_error_file_without_resources"
class = "frictionless_warning_file_without_resources"
)
expect_error(
expect_warning(
read_package(test_path("data/resources_missing.json")),
regexp = paste(
"`file` 'data/resources_missing.json' must have a resources property",
"containing at least one resource."
),
fixed = TRUE
)
expect_warning(
read_package(test_path("data/resources_missing.json")),
regexp = "Use {.fun add_resource} to add resources.",
fixed = TRUE
)

# Resources is empty list
expect_error(
expect_warning(
read_package(test_path("data/resources_empty.json")),
class = "frictionless_error_file_without_resources"
)

# No file remotely
expect_error(
read_package("https://example.com/nofile.json"),
class = "frictionless_error_url_not_found"
class = "frictionless_warning_file_without_resources"
)
})

Expand Down

0 comments on commit b052cec

Please sign in to comment.