Browse Source

Issue more precise error when disconnecting a nonexistent connection

Checks whether the signal exists when issuing an error message when
disconnecting a nonexistent connection. Also prints the callable name.
Maganty Rushyendra 4 years ago
parent
commit
6c026a6814
1 changed files with 6 additions and 1 deletions
  1. 6 1
      core/object/object.cpp

+ 6 - 1
core/object/object.cpp

@@ -1357,7 +1357,12 @@ void Object::_disconnect(const StringName &p_signal, const Callable &p_callable,
 	ERR_FAIL_COND(!target_object);
 
 	SignalData *s = signal_map.getptr(p_signal);
-	ERR_FAIL_COND_MSG(!s, vformat("Nonexistent signal '%s' in %s.", p_signal, to_string()));
+	if (!s) {
+		bool signal_is_valid = ClassDB::has_signal(get_class_name(), p_signal) ||
+							   (!script.is_null() && Ref<Script>(script)->has_script_signal(p_signal));
+		ERR_FAIL_COND_MSG(signal_is_valid, "Attempt to disconnect a nonexistent connection from '" + to_string() + "'. signal: '" + p_signal + "', callable: '" + p_callable + "'.");
+	}
+	ERR_FAIL_COND_MSG(!s, vformat("Disconnecting nonexistent signal '%s' in %s.", p_signal, to_string()));
 
 	ERR_FAIL_COND_MSG(!s->slot_map.has(*p_callable.get_base_comparator()), "Disconnecting nonexistent signal '" + p_signal + "', callable: " + p_callable + ".");