diff --git a/NEWS.md b/NEWS.md index 4e30244..cc5efd8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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). diff --git a/R/read_package.R b/R/read_package.R index d4b69a9..8af3fd3 100644 --- a/R/read_package.R +++ b/R/read_package.R @@ -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" ) } diff --git a/tests/testthat/test-read_package.R b/tests/testthat/test-read_package.R index 65d117a..251e1ae 100644 --- a/tests/testthat/test-read_package.R +++ b/tests/testthat/test-read_package.R @@ -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( @@ -73,12 +73,20 @@ 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", @@ -86,17 +94,16 @@ test_that("read_package() returns error on missing file and properties", { ), 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" ) })