Skip to content

Commit 323ed0a

Browse files
Shreeshriiamitdo
authored andcommitted
Replace asserts with tprintf() and exit(1)
Asserts should not be used for missing or invalid input in the command line! This leads to a bad UX.
1 parent c3ab115 commit 323ed0a

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

training/text2image.cpp

+13-4
Original file line numberDiff line numberDiff line change
@@ -423,11 +423,20 @@ int main(int argc, char** argv) {
423423
}
424424
return EXIT_SUCCESS;
425425
}
426+
426427
// Check validity of input flags.
427-
ASSERT_HOST_MSG(!FLAGS_text.empty(), "Text file missing!\n");
428-
ASSERT_HOST_MSG(!FLAGS_outputbase.empty(), "Output file missing!\n");
429-
ASSERT_HOST_MSG(FLAGS_render_ngrams || FLAGS_unicharset_file.empty(),
430-
"Use --unicharset_file only if --render_ngrams is set.\n");
428+
if (FLAGS_text.empty()) {
429+
tprintf("'--text' option is missing!\n");
430+
exit(1);
431+
}
432+
if (FLAGS_outputbase.empty()) {
433+
tprintf("'--outputbase' option is missing!\n");
434+
exit(1);
435+
}
436+
if (!FLAGS_unicharset_file.empty() && FLAGS_render_ngrams) {
437+
tprintf("Use '--unicharset_file' only if '--render_ngrams' is set.\n");
438+
exit(1);
439+
}
431440

432441
if (!FLAGS_find_fonts && !FontUtils::IsAvailableFont(FLAGS_font.c_str())) {
433442
string pango_name;

0 commit comments

Comments
 (0)