Skip to content

Commit

Permalink
Replace asserts with tprintf() and exit(1)
Browse files Browse the repository at this point in the history
Asserts should not be used for missing or invalid input in the command
line! This leads to a bad UX.
  • Loading branch information
Shreeshrii authored and amitdo committed Jun 14, 2016
1 parent 86acff5 commit c3a7fab
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions training/text2image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,11 +423,20 @@ int main(int argc, char** argv) {
}
return EXIT_SUCCESS;
}

// Check validity of input flags.
ASSERT_HOST_MSG(!FLAGS_text.empty(), "Text file missing!\n");
ASSERT_HOST_MSG(!FLAGS_outputbase.empty(), "Output file missing!\n");
ASSERT_HOST_MSG(FLAGS_render_ngrams || FLAGS_unicharset_file.empty(),
"Use --unicharset_file only if --render_ngrams is set.\n");
if (FLAGS_text.empty()) {
tprintf("'--text' option is missing!\n");
exit(1);
}
if (FLAGS_outputbase.empty()) {
tprintf("'--outputbase' option is missing!\n");
exit(1);
}
if (!FLAGS_unicharset_file.empty() && FLAGS_render_ngrams) {
tprintf("Use '--unicharset_file' only if '--render_ngrams' is set.\n");
exit(1);
}

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

0 comments on commit c3a7fab

Please sign in to comment.