Skip to content

Commit

Permalink
fileio: Replace assert with tprintf() and exit(1)
Browse files Browse the repository at this point in the history
Assertions are good for programming errors, but not for wrong user input.

The new code no longer needs File::ReadFileToStringOrDie, so remove that
method.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil committed Aug 30, 2016
1 parent d093ed4 commit 6ec1a0a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
6 changes: 0 additions & 6 deletions training/fileio.cpp
Expand Up @@ -80,12 +80,6 @@ bool File::ReadFileToString(const string& filename, string* out) {
return in.CloseFile();
}

void File::ReadFileToStringOrDie(const string& filename, string* out) {
ASSERT_HOST_MSG(ReadFileToString(filename, out),
"Failed to read file: %s\n", filename.c_str());
}


string File::JoinPath(const string& prefix, const string& suffix) {
return (!prefix.size() || prefix[prefix.size() - 1] == '/') ?
prefix + suffix : prefix + "/" + suffix;
Expand Down
1 change: 0 additions & 1 deletion training/fileio.h
Expand Up @@ -42,7 +42,6 @@ class File {
// Return true if the file 'filename' is readable.
static bool Readable(const string& filename);

static void ReadFileToStringOrDie(const string& filename, string* out);
static bool ReadFileToString(const string& filename, string* out);

// Helper methods
Expand Down
5 changes: 4 additions & 1 deletion training/text2image.cpp
Expand Up @@ -499,7 +499,10 @@ int main(int argc, char** argv) {

string src_utf8;
// This c_str is NOT redundant!
File::ReadFileToStringOrDie(FLAGS_text.c_str(), &src_utf8);
if (!File::ReadFileToString(FLAGS_text.c_str(), &src_utf8)) {
tprintf("Failed to read file: %s\n", FLAGS_text.c_str());
exit(1);
}

// Remove the unicode mark if present.
if (strncmp(src_utf8.c_str(), "\xef\xbb\xbf", 3) == 0) {
Expand Down

0 comments on commit 6ec1a0a

Please sign in to comment.