I made the following test file
\documentclass{article}
\newcommand{\CheckIfFileExists}[1]{%
\IfFileExists{#1}{OK}{\PackageError{diaa}{File #1 does not exist}{}}%
}
\begin{document}
\CheckIfFileExists{plain}
\CheckIfFileExists{xuaysyeuersss}
\end{document}
If I compile it with TeXmaker, I get

If I compile it with TeXStudio, I get

The conclusion is that we're in presence of a bug in TeXStudio whereby an error message
! Package diaa Error: File xuaysyeuersss does not exist.
See the diaa package documentation for explanation.
Type H <return> for immediate help.
...
l.11 \CheckIfFileExists{xuaysyeuersss}
is parsed by TeXStudio as a warning.
You can misuse expl3 for getting an error message with
\documentclass{article}
\ExplSyntaxOn
\newcommand{\CheckIfFileExists}[1]
{
\file_if_exist:nTF { #1 }
{OK}
{\msg_expandable_error:nnn { diaa } { not~exist } { #1 }}
}
\msg_new:nnnn { diaa } { not~exist }
{
The~file~#1~does~not~exist
}
{}
\ExplSyntaxOff
\begin{document}
\CheckIfFileExists{plain}
\CheckIfFileExists{xuaysyeuersss}
\end{document}

The main issue is that the error message is pretty uninformative. It's much better to ask the maintainers of TeXStudio to be more careful with their log file parsing.
\file_if_exist:nTFis not expandable itself, I'd bet\IfFileExistsis also not... – gusbrs Sep 20 '21 at 20:08\PackageError}{my package}{missing file}{some help}if you made an example using that and said what it is doing wrong perhaps it would be possible to answer your question, otherwise it is hard to guess – David Carlisle Sep 20 '21 at 20:33expl3for “fixing” a bug of the front-end doesn't seem the better way to go. The same experiment on TeXmaker correctly reports error. – egreg Sep 20 '21 at 21:48