Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relax error to warning #266

Merged
merged 2 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
33 changes: 20 additions & 13 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",
"`file` 'data/resources_missing.json' should have a resources property",
"containing at least one resource."
),
fixed = TRUE
)
expect_warning(
read_package(test_path("data/resources_missing.json")),
regexp = "Use `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
Loading