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

fix: make oneshot command return successful exit code #1154

Merged
merged 2 commits into from
May 31, 2023

Conversation

sissbruecker
Copy link
Contributor

@sissbruecker sissbruecker commented May 29, 2023

Summary

While the oneshot command correctly creates output files, the command itself returns an exit code, and logs the following error:

    ! Failed to archive link: FileNotFoundError: [Errno 2] No such file or directory: '<archivebox_location>/archive/1685300775.342935'
Traceback (most recent call last):
  File "/Users/sascha/dev/projects/linkding/venv/archivebox/bin/archivebox", line 8, in <module>
    sys.exit(main())
  File "/Users/sascha/dev/projects/linkding/venv/archivebox/lib/python3.10/site-packages/archivebox/cli/__init__.py", line 140, in main
    run_subcommand(
  File "/Users/sascha/dev/projects/linkding/venv/archivebox/lib/python3.10/site-packages/archivebox/cli/__init__.py", line 80, in run_subcommand
    module.main(args=subcommand_args, stdin=stdin, pwd=pwd)    # type: ignore
  File "/Users/sascha/dev/projects/linkding/venv/archivebox/lib/python3.10/site-packages/archivebox/cli/archivebox_oneshot.py", line 65, in main
    oneshot(
  File "/Users/sascha/dev/projects/linkding/venv/archivebox/lib/python3.10/site-packages/archivebox/util.py", line 114, in typechecked_function
    return func(*args, **kwargs)
  File "/Users/sascha/dev/projects/linkding/venv/archivebox/lib/python3.10/site-packages/archivebox/main.py", line 548, in oneshot
    archive_link(oneshot_link[0], out_dir=out_dir, methods=methods)
  File "/Users/sascha/dev/projects/linkding/venv/archivebox/lib/python3.10/site-packages/archivebox/util.py", line 114, in typechecked_function
    return func(*args, **kwargs)
  File "/Users/sascha/dev/projects/linkding/venv/archivebox/lib/python3.10/site-packages/archivebox/extractors/__init__.py", line 146, in archive_link
    log_link_archiving_finished(link, link.link_dir, is_new, stats, start_ts)
  File "/Users/sascha/dev/projects/linkding/venv/archivebox/lib/python3.10/site-packages/archivebox/logging_util.py", line 396, in log_link_archiving_finished
    size = get_dir_size(link_dir)
  File "/Users/sascha/dev/projects/linkding/venv/archivebox/lib/python3.10/site-packages/archivebox/util.py", line 114, in typechecked_function
    return func(*args, **kwargs)
  File "/Users/sascha/dev/projects/linkding/venv/archivebox/lib/python3.10/site-packages/archivebox/system.py", line 131, in get_dir_size
    for entry in os.scandir(path):
FileNotFoundError: [Errno 2] No such file or directory: '<archivebox_location>/archive/1685300775.342935'

It fails in the log_link_archiving_finished function, where it tries to log information about the link's directory within the archive, which doesn't exist because the oneshot command writes its output into a custom output dir.

This change updates the call to that function to alternatively pass the custom output dir if it has been specified.

I have seen an issue that mentions that the oneshot command is considered deprecated, still I would find it useful and this fix seems to have low impact.

Related issues

No related issue.

Changes these areas

  • Bugfixes
  • Feature behavior
  • Command line interface
  • Configuration options
  • Internal architecture
  • Snapshot data layout on disk

@sissbruecker sissbruecker force-pushed the fix/oneshot_exit_code branch from dcac040 to 40c1225 Compare May 29, 2023 08:01
@@ -162,7 +162,7 @@ def archive_link(link: Link, overwrite: bool=False, methods: Optional[Iterable[s

write_link_details(link, out_dir=out_dir, skip_sql_index=False)

log_link_archiving_finished(link, link.link_dir, is_new, stats, start_ts)
log_link_archiving_finished(link, out_dir, is_new, stats, start_ts)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out_dir should already be the custom output dir or the link's archive dir:

out_dir = out_dir or Path(link.link_dir)

@pirate
Copy link
Member

pirate commented May 31, 2023

thanks!

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

Successfully merging this pull request may close these issues.

2 participants