Skip to content

Commit fa073e4

Browse files
committed
Add a better error when trying to decode a remote pid
1 parent d250917 commit fa073e4

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

include/fine.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,15 @@ template <> struct Decoder<bool> {
409409
template <> struct Decoder<ErlNifPid> {
410410
static ErlNifPid decode(ErlNifEnv *env, const ERL_NIF_TERM &term) {
411411
ErlNifPid pid;
412-
if (!enif_get_local_pid(env, term, &pid)) {
412+
if (!enif_is_pid(env, term)) {
413413
throw std::invalid_argument("decode failed, expected a local pid");
414414
}
415+
if (!enif_get_local_pid(env, term, &pid)) {
416+
// If the term is a PID and it is not local, it means it's a remote PID.
417+
throw std::invalid_argument(
418+
"decode failed, expected a local pid, but got a remote one. NIFs can "
419+
"only send messages to local PIDs and remote PIDs cannot be decoded");
420+
}
415421
return pid;
416422
}
417423
};

0 commit comments

Comments
 (0)