Skip to content

Commit

Permalink
fixup! test: log error
Browse files Browse the repository at this point in the history
Signed-off-by: Darshan Sen <[email protected]>
  • Loading branch information
RaisinTen committed Apr 3, 2022
1 parent 4a75f31 commit 64d9759
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 29 deletions.
55 changes: 27 additions & 28 deletions src/heap_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,7 @@ void BuildEmbedderGraph(const FunctionCallbackInfo<Value>& args) {
namespace {
class FileOutputStream : public v8::OutputStream {
public:
FileOutputStream(Environment* env, int fd, uv_fs_t* req)
: env_(env), fd_(fd), req_(req) {}
FileOutputStream(int fd, uv_fs_t* req) : fd_(fd), req_(req) {}

int GetChunkSize() override {
return 65536; // big chunks == faster
Expand All @@ -230,21 +229,20 @@ class FileOutputStream : public v8::OutputStream {
void EndOfStream() override {}

WriteResult WriteAsciiChunk(char* data, int size) override {
DCHECK(!aborted_);
DCHECK_EQ(status_, 0);
int offset = 0;
while (offset < size) {
uv_buf_t buf = uv_buf_init(data + offset, size - offset);
int num_bytes_written = uv_fs_write(nullptr,
req_,
fd_,
&buf,
1,
-1,
nullptr);
const int num_bytes_written = uv_fs_write(nullptr,
req_,
fd_,
&buf,
1,
-1,
nullptr);
uv_fs_req_cleanup(req_);
if (num_bytes_written < 0) {
aborted_ = true;
env_->ThrowErrnoException(-num_bytes_written, "write");
status_ = num_bytes_written;
return kAbort;
}
DCHECK_LE(num_bytes_written, buf.len);
Expand All @@ -254,13 +252,12 @@ class FileOutputStream : public v8::OutputStream {
return kContinue;
}

bool aborted() const { return aborted_; }
int status() const { return status_; }

private:
Environment* env_;
int fd_;
uv_fs_t* req_;
bool aborted_ = false;
int status_ = 0;
};

class HeapSnapshotStream : public AsyncWrap,
Expand Down Expand Up @@ -353,29 +350,31 @@ inline void TakeSnapshot(Environment* env, v8::OutputStream* out) {

Maybe<void> WriteSnapshot(Environment* env, const char* filename) {
uv_fs_t req;

int fd = uv_fs_open(nullptr,
&req,
filename,
O_WRONLY | O_CREAT | O_TRUNC,
S_IWUSR | S_IRUSR,
nullptr);
int err;

const int fd = uv_fs_open(nullptr,
&req,
filename,
O_WRONLY | O_CREAT | O_TRUNC,
S_IWUSR | S_IRUSR,
nullptr);
uv_fs_req_cleanup(&req);
if (fd < 0) {
env->ThrowErrnoException(-fd, "open");
if ((err = fd) < 0) {
env->ThrowUVException(err, "open", nullptr, filename);
return Nothing<void>();
}

FileOutputStream stream(env, fd, &req);
FileOutputStream stream(fd, &req);
TakeSnapshot(env, &stream);
if (stream.aborted()) {
if ((err = stream.status()) < 0) {
env->ThrowUVException(err, "write", nullptr, filename);
return Nothing<void>();
}

int err = uv_fs_close(nullptr, &req, fd, nullptr);
err = uv_fs_close(nullptr, &req, fd, nullptr);
uv_fs_req_cleanup(&req);
if (err < 0) {
env->ThrowErrnoException(-err, "close");
env->ThrowUVException(err, "close", nullptr, filename);
return Nothing<void>();
}

Expand Down
1 change: 0 additions & 1 deletion test/sequential/test-heapdump.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ process.chdir(tmpdir.path);
assert.throws(() => {
writeHeapSnapshot(directory);
}, (e) => {
console.debug(e);
assert.ok(e, 'writeHeapSnapshot should error');
assert.strictEqual(e.code, 'EISDIR');
assert.strictEqual(e.syscall, 'open');
Expand Down

0 comments on commit 64d9759

Please sign in to comment.