Execution module function file.get_mode() should not exit with error if file not found
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 15.7k
- Forks
- 5.6k
- Avg merge
- 2d 44m
- Merged PRs (30d)
- 80
Description
Description of Issue
I am using salt.file.get_mode() on a file that may not exist in a jinja function:
{% set current_mod = salt.file.get_mode("/tmp/file_that_does_not_exist") %}
When the file does not exist, I get a rendering error. I expect the function to return an error or None or something like that, not fail to render.
Likewise, doing the same operation from the CLI:
sudo salt-call --local file.get_mode /tmp/file_that_does_not_exist
exits with Salt failing. I would have expected that Salt successfully reported that the file does not exist, reporting None or False, etc.
Setup
I think above is sufficient, but will flesh them out if necessary.
Steps to Reproduce Issue
$ touch /tmp/file_that_does_not_exist
$ sudo salt-call --local file.get_mode /tmp/file_that_does_not_exist
local:
0644
$ rm /tmp/file_that_does_not_exist
$ sudo salt-call --local file.get_mode /tmp/file_that_does_not_exist
Error running 'file.get_mode': Path not found: /tmp/file_that_does_not_exist
$ echo $?
1
Versions Report
$ salt-call -V
Salt Version:
Salt: 3005.1
Dependency Versions:
cffi: 1.14.6
cherrypy: 18.6.1
dateutil: 2.8.1
docker-py: Not Installed
gitdb: Not Installed
gitpython: Not Installed
Jinja2: 3.1.0
libgit2: Not Installed
M2Crypto: Not Installed
Mako: Not Installed
msgpack: 1.0.2
msgpack-pure: Not Installed
mysql-python: Not Installed
pycparser: 2.21
pycrypto: Not Installed
pycryptodome: 3.9.8
pygit2: Not Installed
Python: 3.9.16 (main, Nov 1 2022, 00:00:00)
python-gnupg: 0.4.8
PyYAML: 5.4.1
PyZMQ: 23.2.0
smmap: Not Installed
timelib: 0.2.4
Tornado: 4.5.3
ZMQ: 4.3.4
System Versions:
dist: rhel 9.1 Plow
locale: utf-8
machine: x86_64
release: 5.14.0-162.18.1.el9_1.x86_64
system: Linux
version: Red Hat Enterprise Linux 9.1 Plow
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the Salt execution-module entry point for file.get_mode(), then reproduce the missing-path behavior with the Jinja example and the salt-call command in the issue. Check the existing handling and tests for nonexistent paths; done means the function reports a nonfatal result such as None or False without causing rendering or CLI failure, with coverage for both uses.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend, cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100