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

build_site() fails if http user dir cache is present but empty. #2731

Closed
fwimp opened this issue Jul 24, 2024 · 8 comments
Closed

build_site() fails if http user dir cache is present but empty. #2731

fwimp opened this issue Jul 24, 2024 · 8 comments

Comments

@fwimp
Copy link

fwimp commented Jul 24, 2024

This is a very strange one, and I'm not precisely sure how my installation got into this state. For context I am using windows, so can't confirm that this is reproducible on OSX/Linux.

However in the case where the http cache at tools::R_user_dir("pkgdown", "cache"), "http") is present but contains no data, build_site() fails.

The root cause of this failure is in the function cran_link().

see build-home-index.R@L192

It seems that httr2 is reading the cache as present, and trying to load data from it, however given that there is no data, the underlying readRDS() call fails.

Whilst at its root this is possibly overall an httr2 issue more than a pkgdown issue, it'd be useful to either have mitigation for a corrupted httr2 cache hit, or at least a warning to the user to try deleting the http cache file.

Deleting the http cache file fixes the error and the build succeeds.

Steps to reproduce

  1. Open the cache file *.rds located at the directory specified by tools::R_user_dir("pkgdown", "cache"), "http") in a text editor.
  2. Delete all data in the file and save.
  3. Run build_site() as usual.

Full stack traces

Console output

── Building home ───────────────────────────────────────────────────────────────
Reading LICENSE.md
Error: 
! in callr subprocess.
Caused by error in `readRDS(path)`:
! error reading from connection
ℹ See `$stdout` and `$stderr` for standard output and error.
Type .Last.error to see the more details.

Full stack trace (from .Last.error)

Reading LICENSE.md
Error: 
! in callr subprocess.
Caused by error in `readRDS(path)`:
! error reading from connection
ℹ See `$stdout` and `$stderr` for standard output and error.
Type .Last.error to see the more details.
> .Last.error
<callr_error/rlib_error_3_0/rlib_error/error>
Error: 
! in callr subprocess.
Caused by error in `readRDS(path)`:
! error reading from connection
ℹ See `$stdout` and `$stderr` for standard output and error.
---
Backtrace:
1. pkgdown::build_site()
4. pkgdown:::build_site_external(pkg = pkg, examples = examples, run_dont_run = run_dont_run, …
5. callr::r(function(..., cli_colors, hyperlinks, pkgdown_internet) { …
6. callr:::get_result(output = out, options)
7. callr:::throw(callr_remote_error(remerr, output), parent = fix_msg(remerr[[3]]))
---
Subprocess backtrace:
 1. pkgdown::build_site(...)
 2. pkgdown:::build_site_local(pkg = pkg, examples = examples, run_dont_run = run_dont_run, …
 3. pkgdown::build_home(pkg, override = override, preview = FALSE)
 4. pkgdown::build_home_index(pkg, quiet = quiet)
 5. pkgdown:::data_home(pkg)
 8. pkgdown:::print_yaml(list(pagetitle = title, sidebar = data_home_sidebar(pkg, …
 9. base::structure(x, class = "print_yaml")
 10. pkgdown:::data_home_sidebar(pkg, call = call)
 11. pkgdown:::data_home_sidebar_links(pkg)
12. pkgdown:::cran_link(pkg$package)
13. httr2::req_perform(req)
14. httr2:::cache_pre_fetch(req)
15. httr2:::resp_cache_info(cache_get(req))
16. httr2:::resp_cache_expires(resp, control)
17. control %||% resp_cache_control(resp)
18. httr2:::resp_cache_control(resp)
19. httr2::resp_header(resp, "Cache-Control")
20. httr2:::check_response(resp)
21. httr2:::is_response(resp)
22. httr2:::cache_get(req)
23. base::readRDS(path)
24. base::.handleSimpleError(function (e) …
25. global h(simpleError(msg, call))
@fwimp fwimp changed the title build_site() fails if http user dir cache is present but empty. build_site() fails if http user dir cache is present but empty. Jul 24, 2024
@hadley
Copy link
Member

hadley commented Jul 24, 2024

Do you have the latest httr2 installed?

@jayhesselberth
Copy link
Collaborator

The dev version has pkgdown::clean_cache() to address this issue, which is also fixed in the new httr2 release.

@fwimp
Copy link
Author

fwimp commented Jul 25, 2024

Ahh, I'd installed httr2 a few weeks ago, and hadn't seen 1.0.2 come out last week. Installing that fixes the problem at its root.

Also missed #2696 which mentioned this same issue.

Thank you both!

@fwimp fwimp closed this as completed Jul 25, 2024
@fwimp
Copy link
Author

fwimp commented Aug 8, 2024

@hadley Weirdly, this is still happening occasionally on httr2 version 1.0.2! It is inconsistent though as a re-run shortly after fixed the problem.

Not precisely sure where this should go as it's not quite a pkgdown issue, but figured it was best to still document the issue as I saw it.

── Building home ───────────────────────────────────────────────────────────────
Writing authors.html
Reading pkg_dev_notes.md
Writing pkg_dev_notes.html
Reading LICENSE.md
Writing LICENSE.html
Error: 
! in callr subprocess.
Caused by error in `readRDS(path)`:
! error reading from connection
ℹ See `$stdout` and `$stderr` for standard output and error.
Type .Last.error to see the more details.

Backtrace

> .Last.error
<callr_error/rlib_error_3_0/rlib_error/error>
Error: 
! in callr subprocess.
Caused by error in `readRDS(path)`:
! error reading from connection
ℹ See `$stdout` and `$stderr` for standard output and error.
---
Backtrace:
1. pkgdown::build_site()
2. pkgdown:::build_site_external(pkg = pkg, examples = examples, run_dont_run = run_dont_run, …
3. callr::r(function(..., cli_colors, hyperlinks, pkgdown_internet) { …
4. callr:::get_result(output = out, options)
5. callr:::throw(callr_remote_error(remerr, output), parent = fix_msg(remerr[[3]]))
---
Subprocess backtrace:
 1. pkgdown::build_site(...)
 2. pkgdown:::build_site_local(pkg = pkg, examples = examples, run_dont_run = run_dont_run, …
 3. pkgdown::build_home(pkg, override = override, preview = FALSE)
 4. pkgdown::build_home_index(pkg, quiet = quiet)
 5. pkgdown:::data_home(pkg)
 6. pkgdown:::print_yaml(list(pagetitle = title, sidebar = data_home_sidebar(pkg, …
 7. base::structure(x, class = "print_yaml")
 8. pkgdown:::data_home_sidebar(pkg, call = call)
 9. pkgdown:::data_home_sidebar_links(pkg)
10. pkgdown:::cran_link(pkg$package)
11. httr2::req_perform(req)
12. httr2:::cache_pre_fetch(req)
13. httr2:::resp_cache_info(cache_get(req))
14. httr2:::resp_cache_expires(resp, control)
15. control %||% resp_cache_control(resp)
16. httr2:::resp_cache_control(resp)
17. httr2::resp_header(resp, "Cache-Control")
18. httr2:::check_response(resp)
19. httr2:::is_response(resp)
20. httr2:::cache_get(req)
21. base::readRDS(path)
22. base::.handleSimpleError(function (e) …
23. global h(simpleError(msg, call))

@jayhesselberth
Copy link
Collaborator

@fwimp

Try cleaning your cache, then re-build.

# install.pakcages("pak")
pak::pak("r-lib/pkgdown")
pkgdown::clean_cache()
pkgdown::build_site()

@fwimp
Copy link
Author

fwimp commented Aug 8, 2024

Ah alas I had already fixed it by deleting that same cache manually, otherwise I would have tested this route.

Not entirely sure why this continues to happen, should probably shift to an httr2 issue if it happens further.

Thank you!

@francisbarton
Copy link

Cache clearance also fixed the same issue for me

@hadley
Copy link
Member

hadley commented Aug 31, 2024

This bug is definitively fixed in httr2 1.0.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants