Skip to content

Commit 7773e5c

Browse files
authored
Include error information on error opening output file (#2745)
Fixes: #2740
1 parent 282e2e5 commit 7773e5c

3 files changed

Lines changed: 16 additions & 9 deletions

File tree

src/stream.cc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@
2323
#define DUMP_OCTETS_PER_LINE 16
2424
#define DUMP_OCTETS_PER_GROUP 2
2525

26-
#define ERROR0(msg) fprintf(stderr, "%s:%d: " msg, __FILE__, __LINE__)
27-
#define ERROR(fmt, ...) \
28-
fprintf(stderr, "%s:%d: " fmt, __FILE__, __LINE__, __VA_ARGS__)
26+
#define UNIMPLMENTED(msg) fprintf(stderr, "%s:%d: " msg, __FILE__, __LINE__)
27+
#define ERROR(fmt, ...) fprintf(stderr, "wabt: " fmt, __VA_ARGS__)
2928

3029
namespace wabt {
3130

@@ -136,7 +135,8 @@ Result OutputBuffer::WriteToFile(std::string_view filename) const {
136135
std::string filename_str(filename);
137136
FILE* file = fopen(filename_str.c_str(), "wb");
138137
if (!file) {
139-
ERROR("unable to open %s for writing\n", filename_str.c_str());
138+
ERROR("unable to open %s for writing: %s\n", filename_str.c_str(),
139+
strerror(errno));
140140
return Result::Error;
141141
}
142142

@@ -238,7 +238,8 @@ FileStream::FileStream(std::string_view filename, Stream* log_stream)
238238
if (file_) {
239239
should_close_ = true;
240240
} else {
241-
ERROR("fopen name=\"%s\" failed, errno=%d\n", filename_str.c_str(), errno);
241+
ERROR("unable to open %s for writing: %s\n", filename_str.c_str(),
242+
strerror(errno));
242243
}
243244
}
244245

@@ -304,7 +305,7 @@ Result FileStream::MoveDataImpl(size_t dst_offset,
304305
return Result::Ok;
305306
}
306307
// TODO(binji): implement if needed.
307-
ERROR0("FileStream::MoveDataImpl not implemented!\n");
308+
UNIMPLMENTED("FileStream::MoveDataImpl not implemented!\n");
308309
return Result::Error;
309310
}
310311

@@ -313,7 +314,7 @@ Result FileStream::TruncateImpl(size_t size) {
313314
return Result::Error;
314315
}
315316
// TODO(binji): implement if needed.
316-
ERROR0("FileStream::TruncateImpl not implemented!\n");
317+
UNIMPLMENTED("FileStream::TruncateImpl not implemented!\n");
317318
return Result::Error;
318319
}
319320

src/tools/wasm-stats.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
#include "wabt/option-parser.h"
3030
#include "wabt/stream.h"
3131

32-
#define ERROR(fmt, ...) \
33-
fprintf(stderr, "%s:%d: " fmt, __FILE__, __LINE__, __VA_ARGS__)
32+
#define ERROR(fmt, ...) fprintf(stderr, "wabt: " fmt, __VA_ARGS__)
3433

3534
using namespace wabt;
3635

test/dump/bad-output-path.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
;;; RUN: %(wat2wasm)s %(in_file)s -o %(temp_file)s.wasm
2+
;;; RUN: %(wasm-strip)s -o non-existent/out.wasm %(temp_file)s.wasm
3+
;;; ERROR: 1
4+
(module)
5+
(;; STDERR ;;;
6+
wabt: unable to open non-existent/out.wasm for writing: No such file or directory
7+
;;; STDERR ;;)

0 commit comments

Comments
 (0)