Sourcing a non existent file in .profile causes the screen to go black on a fresh install

I recently installed cachy os. The screen turned black after turning on the computer. Since I didnt know what was the issue I reinstalled everything and one by one tested each program and configuration change until I could find the culprit. Among those, one of my configurations was copying the .profile I had on my previous installation. Upon turning the computer off and on again, after writing my password and pressing enter, the screen becomes black and nothing works. Pressing the power button makes the computer turn off. I examined the file and noticed one particular line that might have been the problem.

. $HOME/.cargo/env

At this point .cargo doesnt exist. I commented that line and the problem went away. Just to make sure this was not related to the names I created this line at the end of .profile

. $HOME/something

As expected, since the something file doesn’t exist the screen went black after putting the password. This really seems like a bug, sourcing a non existent file in the .profile file shouldn’t cause such an issue.

If no readable file is found, a non-interactive shell shall abort;
an interactive shell shall write a diagnostic message to standard
error, but this condition shall not be considered a syntax error.

source: man dot

Maybe this is just me but the screen going completely black because the file couldn’t be found seems like the wrong thing. I would rather prefer a huge error message, not to fail silently with no indication of what is the problem. I had to test each configuration one by one until I found the culprit. What would be a better way of finding this issue?

Maybe you can put some logic (like an if statement) to check that the file exists before sourcing it.
I’m not that good in bash, to help you more with this. But you can find plenty of guides online. Also there is a youtube channel “You suck at programming” its all about bash.

You could look for a shell with different characteristics or use tools to test for the existence of a file before trying to source it.

You can use something like this:

FILE=/etc/resolv.conf
if [ -f “$FILE” ]; then
source $FILE
fi

I will check all the files that I end up sourcing and add that check. Thank you. I appreciate it.

But still if I didn’t know that file had a problem how could I find it in the first place.