Show error message when -f fails

This commit is contained in:
Slaren 2023-03-31 20:03:48 +02:00 committed by Pavol Rusnak
parent 3525899277
commit 0d054e292e

View file

@ -66,6 +66,11 @@ bool gpt_params_parse(int argc, char ** argv, gpt_params & params) {
break; break;
} }
std::ifstream file(argv[i]); std::ifstream file(argv[i]);
if (!file) {
fprintf(stderr, "error: failed to open file '%s'\n", argv[i]);
invalid_param = true;
break;
}
std::copy(std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>(), back_inserter(params.prompt)); std::copy(std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>(), back_inserter(params.prompt));
if (params.prompt.back() == '\n') { if (params.prompt.back() == '\n') {
params.prompt.pop_back(); params.prompt.pop_back();