Skip to content

Commit

Permalink
check error in wrapper instead of in rust
Browse files Browse the repository at this point in the history
  • Loading branch information
jackyzha0 committed Oct 4, 2024
1 parent efe4ef2 commit 5ecd2f7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
8 changes: 0 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,14 +303,6 @@ impl Pty {
#[napi]
#[allow(dead_code)]
fn pty_resize(fd: i32, size: Size) -> Result<(), napi::Error> {
// check the fd is still valid before we try to resize
if unsafe { libc::fcntl(fd, libc::F_GETFD) } == -1 {
return Err(napi::Error::new(
napi::Status::GenericFailure,
"fd not valid for resize",
));
}

let window_size = Winsize {
ws_col: size.cols,
ws_row: size.rows,
Expand Down
13 changes: 12 additions & 1 deletion wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,18 @@ export class Pty {
return;
}

ptyResize(this.#fd, size);
try {
ptyResize(this.#fd, size);
} catch (e: unknown) {
if (e instanceof Error && 'code' in e && e.code === 'EBADF') {
// EBADF means the file descriptor is invalid. This can happen if the PTY has already
// exited but we don't know about it yet. In that case, we just ignore the error.
return;
}

// otherwise, rethrow
throw e;
}
}

get pid() {
Expand Down

0 comments on commit 5ecd2f7

Please sign in to comment.