Skip to content

Commit 6ec1a0a

Browse files
committed
fileio: Replace assert with tprintf() and exit(1)
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>
1 parent d093ed4 commit 6ec1a0a

File tree

3 files changed

+4
-8
lines changed

3 files changed

+4
-8
lines changed

training/fileio.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,6 @@ bool File::ReadFileToString(const string& filename, string* out) {
8080
return in.CloseFile();
8181
}
8282

83-
void File::ReadFileToStringOrDie(const string& filename, string* out) {
84-
ASSERT_HOST_MSG(ReadFileToString(filename, out),
85-
"Failed to read file: %s\n", filename.c_str());
86-
}
87-
88-
8983
string File::JoinPath(const string& prefix, const string& suffix) {
9084
return (!prefix.size() || prefix[prefix.size() - 1] == '/') ?
9185
prefix + suffix : prefix + "/" + suffix;

training/fileio.h

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ class File {
4242
// Return true if the file 'filename' is readable.
4343
static bool Readable(const string& filename);
4444

45-
static void ReadFileToStringOrDie(const string& filename, string* out);
4645
static bool ReadFileToString(const string& filename, string* out);
4746

4847
// Helper methods

training/text2image.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,10 @@ int main(int argc, char** argv) {
499499

500500
string src_utf8;
501501
// This c_str is NOT redundant!
502-
File::ReadFileToStringOrDie(FLAGS_text.c_str(), &src_utf8);
502+
if (!File::ReadFileToString(FLAGS_text.c_str(), &src_utf8)) {
503+
tprintf("Failed to read file: %s\n", FLAGS_text.c_str());
504+
exit(1);
505+
}
503506

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

0 commit comments

Comments
 (0)