\documentclass{article}
\makeatletter
\newcommand{\thereisnosuchfile}{%
\@latex@error{No file to input}{The file you asked for doesn't exist}%
}
\makeatother
\begin{document}
\InputIfFileExists{dummy}{}{\thereisnosuchfile}
\input{dummy}
\end{document}
What's the difference? In the first case there is no request for another file name. On the other hand, in the second case, just hitting return would exit from the loop by inputting the empty .tex file.
! LaTeX Error: No file to input.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.10 ...tIfFileExists{dummy}{}{\thereisnosuchfile}
?
! LaTeX Error: File `dummy.tex' not found.
Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: tex)
Enter file name: <<hit return>>
(/usr/local/texlive/2020/texmf-dist/tex/latex/tools/.tex File ignored)
If you add \stop at the end of the definition of \thereisnosuchfile, the LaTeX run would stop after hitting return.
An expl3 version:
\documentclass{article}
\ExplSyntaxOn
\NewDocumentCommand{\saferinput}{m}
{
\file_if_exist_input:nF { #1 } { \msg_error:nnn { diaa } { no-file } { #1 } }
}
\msg_new:nnnn { diaa } { no-file }
{ No~file~'#1' }
{ The~file~'#1'~you~asked~for~does~not~exist }
\ExplSyntaxOff
\begin{document}
\saferinput{dummy}
\end{document}
Console output
! Package diaa Error: No file 'dummy'
For immediate help type H <return>.
...
l.15 \saferinput{dummy}
? h
The file 'dummy' you asked for does not exist
?
\inputinstead of\InputIfFileExistsas\inputwill give an error for a missing file, the point of\InputIfFileExistsis exactly to avoid the error. – David Carlisle Dec 23 '20 at 11:41\documentclass{article} \begin{document} \input{dummy} \end{document}doesn't stop when building withlualatex.exe -synctex=1 -shell-escape -file-line-error -halt-on-error "filemissing".tex– Diaa Dec 23 '20 at 11:50-interaction=nonstopmodeinstead of\halt-on-errorbut you have still provided no log for the version in the question. That should run to completion with no error at all. – David Carlisle Dec 23 '20 at 11:54stopbutton of texstudio. – Diaa Dec 23 '20 at 11:57warning (pdf backend): no pages of output.– David Carlisle Dec 23 '20 at 12:15:D– Diaa Dec 23 '20 at 12:16expl3solution is great, but I would like to have the solution in the old school way with typing the missing file name in the log. – Diaa Dec 23 '20 at 12:25