Skip to content

FileContents does not return None if file does not exist #1454

@NichtJens

Description

@NichtJens

Describe the bug

The docs of FileContents say:

Returns None if the file doest not exist.

However, it actually errors and stops the script.

(Also, note the "doest" typo.)

To Reproduce

from pyinfra import host
from pyinfra.facts.files import FileContents

host.get_fact(FileContents, "doesnotexist")
pyinfra localhost test.py
--> Preparing operation files...
    Loading: test.py
    [localhost] cat: doesnotexist: No such file or directory
    [localhost] Error: could not load fact: files.FileContents path=doesnotexist

Expected behavior

The current behavior could be correct in the sense that asking for the contents of a file that does not exist may be an error. OTOH, returning None for non-existent files also makes sense. So:

  • either the documentation should be corrected, or
  • it should return None if the file does not exist.

The typo ("doest") should be fixed. Sha1File has the same typo.

Meta

  • Include output of pyinfra --support.
  • How was pyinfra installed (source/pip)?
  • Include pyinfra-debug.log (if one was created)
  • Consider including output with -vv and --debug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions