A valid os-release(5) file is not expected to have any commands in it. Hence, there's no chance of a non-zero exit code from the last command inside /etc/os-release getting forwarded as the exit code of the attempt to source it [2], and getting misinterpreted as the file being absent. The /etc/os-release file is owned by root. It's assumed that the root user knows what they are doing and has put in place a sane file.
It's not mandatory for
/etc/os-releaseto be present. Theos-release(5)manual says [1]:A valid
os-release(5)file is not expected to have any commands in it. Hence, there's no chance of a non-zero exit code from the last command inside/etc/os-releasegetting forwarded as the exit code of the attempt to source it [2], and getting misinterpreted as the file being absent. The/etc/os-releasefile is owned byroot. It's assumed that therootuser knows what they are doing and has put in place a sane file.[1] https://www.freedesktop.org/software/systemd/man/os-release.html
[2] https://www.gnu.org/software/bash/manual/html_node/Bourne-Shell-Builtins.html