diff options
author | qarmin <mikrutrafal54@gmail.com> | 2019-09-25 10:28:50 +0200 |
---|---|---|
committer | qarmin <mikrutrafal54@gmail.com> | 2019-09-25 10:28:50 +0200 |
commit | 17732fe698b835c29f77c84f329b2ed6cab215ce (patch) | |
tree | b95c08185e886dc6410ba8646e5ff839382b4e01 | |
parent | e9f49a6d5ac88a6afca8a16f91a05f4fcdf5a589 (diff) |
Added some obvious errors explanations
125 files changed, 435 insertions, 458 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 5161f8bab2..30aaa0e646 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -145,13 +145,13 @@ _ResourceLoader::_ResourceLoader() { } Error _ResourceSaver::save(const String &p_path, const RES &p_resource, SaverFlags p_flags) { - ERR_FAIL_COND_V_MSG(p_resource.is_null(), ERR_INVALID_PARAMETER, "Can't save empty resource to path: " + String(p_path) + "."); + ERR_FAIL_COND_V_MSG(p_resource.is_null(), ERR_INVALID_PARAMETER, "Can't save empty resource to path '" + String(p_path) + "'."); return ResourceSaver::save(p_path, p_resource, p_flags); } PoolVector<String> _ResourceSaver::get_recognized_extensions(const RES &p_resource) { - ERR_FAIL_COND_V(p_resource.is_null(), PoolVector<String>()); + ERR_FAIL_COND_V_MSG(p_resource.is_null(), PoolVector<String>(), "It's not a reference to a valid Resource object."); List<String> exts; ResourceSaver::get_recognized_extensions(p_resource, &exts); PoolVector<String> ret; @@ -755,7 +755,7 @@ int64_t _OS::get_unix_time_from_datetime(Dictionary datetime) const { ERR_FAIL_COND_V_MSG(month > 12 || month == 0, 0, "Invalid month value of: " + itos(month) + "."); // Do this check after month is tested as valid - ERR_FAIL_COND_V_MSG(day > MONTH_DAYS_TABLE[LEAPYEAR(year)][month - 1] || day == 0, 0, "Invalid day value of: " + itos(day) + " which is larger than " + itos(MONTH_DAYS_TABLE[LEAPYEAR(year)][month - 1]) + " or 0."); + ERR_FAIL_COND_V_MSG(day > MONTH_DAYS_TABLE[LEAPYEAR(year)][month - 1] || day == 0, 0, "Invalid day value of '" + itos(day) + "' which is larger than '" + itos(MONTH_DAYS_TABLE[LEAPYEAR(year)][month - 1]) + "' or 0."); // Calculate all the seconds from months past in this year uint64_t SECONDS_FROM_MONTHS_PAST_THIS_YEAR = DAYS_PAST_THIS_YEAR_TABLE[LEAPYEAR(year)][month - 1] * SECONDS_PER_DAY; @@ -1866,92 +1866,92 @@ bool _File::is_open() const { } String _File::get_path() const { - ERR_FAIL_COND_V(!f, ""); + ERR_FAIL_COND_V_MSG(!f, "", "File must be opened before use."); return f->get_path(); } String _File::get_path_absolute() const { - ERR_FAIL_COND_V(!f, ""); + ERR_FAIL_COND_V_MSG(!f, "", "File must be opened before use."); return f->get_path_absolute(); } void _File::seek(int64_t p_position) { - ERR_FAIL_COND(!f); + ERR_FAIL_COND_MSG(!f, "File must be opened before use."); f->seek(p_position); } void _File::seek_end(int64_t p_position) { - ERR_FAIL_COND(!f); + ERR_FAIL_COND_MSG(!f, "File must be opened before use."); f->seek_end(p_position); } int64_t _File::get_position() const { - ERR_FAIL_COND_V(!f, 0); + ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); return f->get_position(); } int64_t _File::get_len() const { - ERR_FAIL_COND_V(!f, 0); + ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); return f->get_len(); } bool _File::eof_reached() const { - ERR_FAIL_COND_V(!f, false); + ERR_FAIL_COND_V_MSG(!f, false, "File must be opened before use."); return f->eof_reached(); } uint8_t _File::get_8() const { - ERR_FAIL_COND_V(!f, 0); + ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); return f->get_8(); } uint16_t _File::get_16() const { - ERR_FAIL_COND_V(!f, 0); + ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); return f->get_16(); } uint32_t _File::get_32() const { - ERR_FAIL_COND_V(!f, 0); + ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); return f->get_32(); } uint64_t _File::get_64() const { - ERR_FAIL_COND_V(!f, 0); + ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); return f->get_64(); } float _File::get_float() const { - ERR_FAIL_COND_V(!f, 0); + ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); return f->get_float(); } double _File::get_double() const { - ERR_FAIL_COND_V(!f, 0); + ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); return f->get_double(); } real_t _File::get_real() const { - ERR_FAIL_COND_V(!f, 0); + ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); return f->get_real(); } PoolVector<uint8_t> _File::get_buffer(int p_length) const { PoolVector<uint8_t> data; - ERR_FAIL_COND_V(!f, data); + ERR_FAIL_COND_V_MSG(!f, data, "File must be opened before use."); - ERR_FAIL_COND_V(p_length < 0, data); + ERR_FAIL_COND_V_MSG(p_length < 0, data, "Length of buffer cannot be smaller than 0."); if (p_length == 0) return data; Error err = data.resize(p_length); - ERR_FAIL_COND_V(err != OK, data); + ERR_FAIL_COND_V_MSG(err != OK, data, "Can't resize data to " + itos(p_length) + " elements."); PoolVector<uint8_t>::Write w = data.write(); int len = f->get_buffer(&w[0], p_length); @@ -1967,7 +1967,7 @@ PoolVector<uint8_t> _File::get_buffer(int p_length) const { String _File::get_as_text() const { - ERR_FAIL_COND_V(!f, String()); + ERR_FAIL_COND_V_MSG(!f, String(), "File must be opened before use."); String text; size_t original_pos = f->get_position(); @@ -1997,12 +1997,12 @@ String _File::get_sha256(const String &p_path) const { String _File::get_line() const { - ERR_FAIL_COND_V(!f, String()); + ERR_FAIL_COND_V_MSG(!f, String(), "File must be opened before use."); return f->get_line(); } Vector<String> _File::get_csv_line(const String &p_delim) const { - ERR_FAIL_COND_V(!f, Vector<String>()); + ERR_FAIL_COND_V_MSG(!f, Vector<String>(), "File must be opened before use."); return f->get_csv_line(p_delim); } @@ -2031,83 +2031,83 @@ Error _File::get_error() const { void _File::store_8(uint8_t p_dest) { - ERR_FAIL_COND(!f); + ERR_FAIL_COND_MSG(!f, "File must be opened before use."); f->store_8(p_dest); } void _File::store_16(uint16_t p_dest) { - ERR_FAIL_COND(!f); + ERR_FAIL_COND_MSG(!f, "File must be opened before use."); f->store_16(p_dest); } void _File::store_32(uint32_t p_dest) { - ERR_FAIL_COND(!f); + ERR_FAIL_COND_MSG(!f, "File must be opened before use."); f->store_32(p_dest); } void _File::store_64(uint64_t p_dest) { - ERR_FAIL_COND(!f); + ERR_FAIL_COND_MSG(!f, "File must be opened before use."); f->store_64(p_dest); } void _File::store_float(float p_dest) { - ERR_FAIL_COND(!f); + ERR_FAIL_COND_MSG(!f, "File must be opened before use."); f->store_float(p_dest); } void _File::store_double(double p_dest) { - ERR_FAIL_COND(!f); + ERR_FAIL_COND_MSG(!f, "File must be opened before use."); f->store_double(p_dest); } void _File::store_real(real_t p_real) { - ERR_FAIL_COND(!f); + ERR_FAIL_COND_MSG(!f, "File must be opened before use."); f->store_real(p_real); } void _File::store_string(const String &p_string) { - ERR_FAIL_COND(!f); + ERR_FAIL_COND_MSG(!f, "File must be opened before use."); f->store_string(p_string); } void _File::store_pascal_string(const String &p_string) { - ERR_FAIL_COND(!f); + ERR_FAIL_COND_MSG(!f, "File must be opened before use."); f->store_pascal_string(p_string); }; String _File::get_pascal_string() { - ERR_FAIL_COND_V(!f, ""); + ERR_FAIL_COND_V_MSG(!f, "", "File must be opened before use."); return f->get_pascal_string(); }; void _File::store_line(const String &p_string) { - ERR_FAIL_COND(!f); + ERR_FAIL_COND_MSG(!f, "File must be opened before use."); f->store_line(p_string); } void _File::store_csv_line(const Vector<String> &p_values, const String &p_delim) { - ERR_FAIL_COND(!f); + ERR_FAIL_COND_MSG(!f, "File must be opened before use."); f->store_csv_line(p_values, p_delim); } void _File::store_buffer(const PoolVector<uint8_t> &p_buffer) { - ERR_FAIL_COND(!f); + ERR_FAIL_COND_MSG(!f, "File must be opened before use."); int len = p_buffer.size(); if (len == 0) @@ -2125,17 +2125,17 @@ bool _File::file_exists(const String &p_name) const { void _File::store_var(const Variant &p_var, bool p_full_objects) { - ERR_FAIL_COND(!f); + ERR_FAIL_COND_MSG(!f, "File must be opened before use."); int len; Error err = encode_variant(p_var, NULL, len, p_full_objects); - ERR_FAIL_COND(err != OK); + ERR_FAIL_COND_MSG(err != OK, "Error when trying to encode Variant."); PoolVector<uint8_t> buff; buff.resize(len); PoolVector<uint8_t>::Write w = buff.write(); err = encode_variant(p_var, &w[0], len, p_full_objects); - ERR_FAIL_COND(err != OK); + ERR_FAIL_COND_MSG(err != OK, "Error when trying to encode Variant."); w.release(); store_32(len); @@ -2144,7 +2144,7 @@ void _File::store_var(const Variant &p_var, bool p_full_objects) { Variant _File::get_var(bool p_allow_objects) const { - ERR_FAIL_COND_V(!f, Variant()); + ERR_FAIL_COND_V_MSG(!f, Variant(), "File must be opened before use."); uint32_t len = get_32(); PoolVector<uint8_t> buff = get_buffer(len); ERR_FAIL_COND_V((uint32_t)buff.size() != len, Variant()); @@ -2153,7 +2153,7 @@ Variant _File::get_var(bool p_allow_objects) const { Variant v; Error err = decode_variant(v, &r[0], len, NULL, p_allow_objects); - ERR_FAIL_COND_V(err != OK, Variant()); + ERR_FAIL_COND_V_MSG(err != OK, Variant(), "Error when trying to encode Variant."); return v; } @@ -2258,7 +2258,7 @@ Error _Directory::open(const String &p_path) { Error _Directory::list_dir_begin(bool p_skip_navigational, bool p_skip_hidden) { - ERR_FAIL_COND_V(!d, ERR_UNCONFIGURED); + ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use."); _list_skip_navigational = p_skip_navigational; _list_skip_hidden = p_skip_hidden; @@ -2268,7 +2268,7 @@ Error _Directory::list_dir_begin(bool p_skip_navigational, bool p_skip_hidden) { String _Directory::get_next() { - ERR_FAIL_COND_V(!d, ""); + ERR_FAIL_COND_V_MSG(!d, "", "Directory must be opened before use."); String next = d->get_next(); while (next != "" && ((_list_skip_navigational && (next == "." || next == "..")) || (_list_skip_hidden && d->current_is_hidden()))) { @@ -2279,44 +2279,44 @@ String _Directory::get_next() { } bool _Directory::current_is_dir() const { - ERR_FAIL_COND_V(!d, false); + ERR_FAIL_COND_V_MSG(!d, false, "Directory must be opened before use."); return d->current_is_dir(); } void _Directory::list_dir_end() { - ERR_FAIL_COND(!d); + ERR_FAIL_COND_MSG(!d, "Directory must be opened before use."); d->list_dir_end(); } int _Directory::get_drive_count() { - ERR_FAIL_COND_V(!d, 0); + ERR_FAIL_COND_V_MSG(!d, 0, "Directory must be opened before use."); return d->get_drive_count(); } String _Directory::get_drive(int p_drive) { - ERR_FAIL_COND_V(!d, ""); + ERR_FAIL_COND_V_MSG(!d, "", "Directory must be opened before use."); return d->get_drive(p_drive); } int _Directory::get_current_drive() { - ERR_FAIL_COND_V(!d, 0); + ERR_FAIL_COND_V_MSG(!d, 0, "Directory must be opened before use."); return d->get_current_drive(); } Error _Directory::change_dir(String p_dir) { - ERR_FAIL_COND_V(!d, ERR_UNCONFIGURED); + ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use."); return d->change_dir(p_dir); } String _Directory::get_current_dir() { - ERR_FAIL_COND_V(!d, ""); + ERR_FAIL_COND_V_MSG(!d, "", "Directory must be opened before use."); return d->get_current_dir(); } Error _Directory::make_dir(String p_dir) { - ERR_FAIL_COND_V(!d, ERR_UNCONFIGURED); + ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use."); if (!p_dir.is_rel_path()) { DirAccess *d = DirAccess::create_for_path(p_dir); Error err = d->make_dir(p_dir); @@ -2327,7 +2327,7 @@ Error _Directory::make_dir(String p_dir) { } Error _Directory::make_dir_recursive(String p_dir) { - ERR_FAIL_COND_V(!d, ERR_UNCONFIGURED); + ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use."); if (!p_dir.is_rel_path()) { DirAccess *d = DirAccess::create_for_path(p_dir); Error err = d->make_dir_recursive(p_dir); @@ -2339,7 +2339,7 @@ Error _Directory::make_dir_recursive(String p_dir) { bool _Directory::file_exists(String p_file) { - ERR_FAIL_COND_V(!d, false); + ERR_FAIL_COND_V_MSG(!d, false, "Directory must be opened before use."); if (!p_file.is_rel_path()) { return FileAccess::exists(p_file); @@ -2349,7 +2349,7 @@ bool _Directory::file_exists(String p_file) { } bool _Directory::dir_exists(String p_dir) { - ERR_FAIL_COND_V(!d, false); + ERR_FAIL_COND_V_MSG(!d, false, "Directory must be opened before use."); if (!p_dir.is_rel_path()) { DirAccess *d = DirAccess::create_for_path(p_dir); @@ -2364,18 +2364,18 @@ bool _Directory::dir_exists(String p_dir) { int _Directory::get_space_left() { - ERR_FAIL_COND_V(!d, 0); + ERR_FAIL_COND_V_MSG(!d, 0, "Directory must be opened before use."); return d->get_space_left() / 1024 * 1024; //return value in megabytes, given binding is int } Error _Directory::copy(String p_from, String p_to) { - ERR_FAIL_COND_V(!d, ERR_UNCONFIGURED); + ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use."); return d->copy(p_from, p_to); } Error _Directory::rename(String p_from, String p_to) { - ERR_FAIL_COND_V(!d, ERR_UNCONFIGURED); + ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use."); if (!p_from.is_rel_path()) { DirAccess *d = DirAccess::create_for_path(p_from); Error err = d->rename(p_from, p_to); @@ -2387,7 +2387,7 @@ Error _Directory::rename(String p_from, String p_to) { } Error _Directory::remove(String p_name) { - ERR_FAIL_COND_V(!d, ERR_UNCONFIGURED); + ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use."); if (!p_name.is_rel_path()) { DirAccess *d = DirAccess::create_for_path(p_name); Error err = d->remove(p_name); @@ -2442,14 +2442,14 @@ String _Marshalls::variant_to_base64(const Variant &p_var, bool p_full_objects) int len; Error err = encode_variant(p_var, NULL, len, p_full_objects); - ERR_FAIL_COND_V(err != OK, ""); + ERR_FAIL_COND_V_MSG(err != OK, "", "Error when trying to encode Variant."); PoolVector<uint8_t> buff; buff.resize(len); PoolVector<uint8_t>::Write w = buff.write(); err = encode_variant(p_var, &w[0], len, p_full_objects); - ERR_FAIL_COND_V(err != OK, ""); + ERR_FAIL_COND_V_MSG(err != OK, "", "Error when trying to encode Variant."); String ret = CryptoCore::b64_encode_str(&w[0], len); ERR_FAIL_COND_V(ret == "", ret); @@ -2471,7 +2471,7 @@ Variant _Marshalls::base64_to_variant(const String &p_str, bool p_allow_objects) Variant v; Error err = decode_variant(v, &w[0], len, NULL, p_allow_objects); - ERR_FAIL_COND_V(err != OK, Variant()); + ERR_FAIL_COND_V_MSG(err != OK, Variant(), "Error when trying to decode Variant."); return v; }; @@ -2638,13 +2638,13 @@ void _Thread::_start_func(void *ud) { } } - ERR_FAIL_MSG("Could not call function '" + t->target_method.operator String() + "'' starting thread ID: " + t->get_id() + " Reason: " + reason + "."); + ERR_FAIL_MSG("Could not call function '" + t->target_method.operator String() + "' to start thread " + t->get_id() + ": " + reason + "."); } } Error _Thread::start(Object *p_instance, const StringName &p_method, const Variant &p_userdata, Priority p_priority) { - ERR_FAIL_COND_V(active, ERR_ALREADY_IN_USE); + ERR_FAIL_COND_V_MSG(active, ERR_ALREADY_IN_USE, "Thread already started."); ERR_FAIL_COND_V(!p_instance, ERR_INVALID_PARAMETER); ERR_FAIL_COND_V(p_method == StringName(), ERR_INVALID_PARAMETER); ERR_FAIL_INDEX_V(p_priority, PRIORITY_MAX, ERR_INVALID_PARAMETER); @@ -2685,8 +2685,8 @@ bool _Thread::is_active() const { } Variant _Thread::wait_to_finish() { - ERR_FAIL_COND_V(!thread, Variant()); - ERR_FAIL_COND_V(!active, Variant()); + ERR_FAIL_COND_V_MSG(!thread, Variant(), "Thread must exist to wait for its completion."); + ERR_FAIL_COND_V_MSG(!active, Variant(), "Thread must be active to wait for its completion."); Thread::wait_to_finish(thread); Variant r = ret; active = false; diff --git a/core/class_db.cpp b/core/class_db.cpp index 3ad59bc309..f52937bdca 100644 --- a/core/class_db.cpp +++ b/core/class_db.cpp @@ -340,7 +340,7 @@ StringName ClassDB::get_parent_class(const StringName &p_class) { OBJTYPE_RLOCK; ClassInfo *ti = classes.getptr(p_class); - ERR_FAIL_COND_V(!ti, StringName()); + ERR_FAIL_COND_V_MSG(!ti, StringName(), "Cannot get class '" + String(p_class) + "'."); return ti->inherits; } @@ -350,7 +350,7 @@ ClassDB::APIType ClassDB::get_api_type(const StringName &p_class) { ClassInfo *ti = classes.getptr(p_class); - ERR_FAIL_COND_V(!ti, API_NONE); + ERR_FAIL_COND_V_MSG(!ti, API_NONE, "Cannot get class '" + String(p_class) + "'."); return ti->api; } @@ -375,7 +375,7 @@ uint64_t ClassDB::get_api_hash(APIType p_api) { for (List<StringName>::Element *E = names.front(); E; E = E->next()) { ClassInfo *t = classes.getptr(E->get()); - ERR_FAIL_COND_V(!t, 0); + ERR_FAIL_COND_V_MSG(!t, 0, "Cannot get class '" + String(E->get()) + "'."); if (t->api != p_api || !t->exposed) continue; hash = hash_djb2_one_64(t->name.hash(), hash); @@ -528,8 +528,8 @@ Object *ClassDB::instance(const StringName &p_class) { ti = classes.getptr(compat_classes[p_class]); } } - ERR_FAIL_COND_V(!ti, NULL); - ERR_FAIL_COND_V(ti->disabled, NULL); + ERR_FAIL_COND_V_MSG(!ti, NULL, "Cannot get class '" + String(p_class) + "'."); + ERR_FAIL_COND_V_MSG(ti->disabled, NULL, "Class '" + String(p_class) + "' is disabled."); ERR_FAIL_COND_V(!ti->creation_func, NULL); } #ifdef TOOLS_ENABLED @@ -545,7 +545,7 @@ bool ClassDB::can_instance(const StringName &p_class) { OBJTYPE_RLOCK; ClassInfo *ti = classes.getptr(p_class); - ERR_FAIL_COND_V(!ti, false); + ERR_FAIL_COND_V_MSG(!ti, false, "Cannot get class '" + String(p_class) + "'."); #ifdef TOOLS_ENABLED if (ti->api == API_EDITOR && !Engine::get_singleton()->is_editor_hint()) { return false; @@ -560,7 +560,7 @@ void ClassDB::_add_class2(const StringName &p_class, const StringName &p_inherit const StringName &name = p_class; - ERR_FAIL_COND(classes.has(name)); + ERR_FAIL_COND_MSG(classes.has(name), "Class '" + String(p_class) + "' already exists."); classes[name] = ClassInfo(); ClassInfo &ti = classes[name]; @@ -836,7 +836,7 @@ void ClassDB::add_signal(StringName p_class, const MethodInfo &p_signal) { #ifdef DEBUG_METHODS_ENABLED ClassInfo *check = type; while (check) { - ERR_FAIL_COND_MSG(check->signal_map.has(sname), "Type " + String(p_class) + " already has signal: " + String(sname) + "."); + ERR_FAIL_COND_MSG(check->signal_map.has(sname), "Class '" + String(p_class) + "' already has signal '" + String(sname) + "'."); check = check->inherits_ptr; } #endif @@ -922,10 +922,10 @@ void ClassDB::add_property(StringName p_class, const PropertyInfo &p_pinfo, cons mb_set = get_method(p_class, p_setter); #ifdef DEBUG_METHODS_ENABLED - ERR_FAIL_COND_MSG(!mb_set, "Invalid setter: " + p_class + "::" + p_setter + " for property: " + p_pinfo.name + "."); + ERR_FAIL_COND_MSG(!mb_set, "Invalid setter '" + p_class + "::" + p_setter + "' for property '" + p_pinfo.name + "'."); int exp_args = 1 + (p_index >= 0 ? 1 : 0); - ERR_FAIL_COND_MSG(mb_set->get_argument_count() != exp_args, "Invalid function for setter: " + p_class + "::" + p_setter + " for property: " + p_pinfo.name + "."); + ERR_FAIL_COND_MSG(mb_set->get_argument_count() != exp_args, "Invalid function for setter '" + p_class + "::" + p_setter + " for property '" + p_pinfo.name + "'."); #endif } @@ -935,15 +935,15 @@ void ClassDB::add_property(StringName p_class, const PropertyInfo &p_pinfo, cons mb_get = get_method(p_class, p_getter); #ifdef DEBUG_METHODS_ENABLED - ERR_FAIL_COND_MSG(!mb_get, "Invalid getter: " + p_class + "::" + p_getter + " for property: " + p_pinfo.name + "."); + ERR_FAIL_COND_MSG(!mb_get, "Invalid getter '" + p_class + "::" + p_getter + "' for property '" + p_pinfo.name + "'."); int exp_args = 0 + (p_index >= 0 ? 1 : 0); - ERR_FAIL_COND_MSG(mb_get->get_argument_count() != exp_args, "Invalid function for getter: " + p_class + "::" + p_getter + " for property: " + p_pinfo.name + "."); + ERR_FAIL_COND_MSG(mb_get->get_argument_count() != exp_args, "Invalid function for getter '" + p_class + "::" + p_getter + "' for property: '" + p_pinfo.name + "'."); #endif } #ifdef DEBUG_METHODS_ENABLED - ERR_FAIL_COND_MSG(type->property_setget.has(p_pinfo.name), "Object " + p_class + " already has property: " + p_pinfo.name + "."); + ERR_FAIL_COND_MSG(type->property_setget.has(p_pinfo.name), "Object '" + p_class + "' already has property '" + p_pinfo.name + "'."); #endif OBJTYPE_WLOCK @@ -1228,20 +1228,20 @@ MethodBind *ClassDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind, const c ClassInfo *type = classes.getptr(instance_type); if (!type) { memdelete(p_bind); - ERR_FAIL_V_MSG(NULL, "Couldn't bind method '" + mdname + "' for instance: " + instance_type + "."); + ERR_FAIL_V_MSG(NULL, "Couldn't bind method '" + mdname + "' for instance '" + instance_type + "'."); } if (type->method_map.has(mdname)) { memdelete(p_bind); // overloading not supported - ERR_FAIL_V_MSG(NULL, "Method already bound: " + instance_type + "::" + mdname + "."); + ERR_FAIL_V_MSG(NULL, "Method already bound '" + instance_type + "::" + mdname + "'."); } #ifdef DEBUG_METHODS_ENABLED if (method_name.args.size() > p_bind->get_argument_count()) { memdelete(p_bind); - ERR_FAIL_V_MSG(NULL, "Method definition provides more arguments than the method actually has: " + instance_type + "::" + mdname + "."); + ERR_FAIL_V_MSG(NULL, "Method definition provides more arguments than the method actually has '" + instance_type + "::" + mdname + "'."); } p_bind->set_argument_names(method_name.args); @@ -1265,7 +1265,7 @@ MethodBind *ClassDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind, const c } void ClassDB::add_virtual_method(const StringName &p_class, const MethodInfo &p_method, bool p_virtual) { - ERR_FAIL_COND(!classes.has(p_class)); + ERR_FAIL_COND_MSG(!classes.has(p_class), "Request for nonexistent class '" + p_class + "'."); OBJTYPE_WLOCK; @@ -1280,7 +1280,7 @@ void ClassDB::add_virtual_method(const StringName &p_class, const MethodInfo &p_ void ClassDB::get_virtual_methods(const StringName &p_class, List<MethodInfo> *p_methods, bool p_no_inheritance) { - ERR_FAIL_COND(!classes.has(p_class)); + ERR_FAIL_COND_MSG(!classes.has(p_class), "Request for nonexistent class '" + p_class + "'."); #ifdef DEBUG_METHODS_ENABLED @@ -1304,7 +1304,7 @@ void ClassDB::set_class_enabled(StringName p_class, bool p_enable) { OBJTYPE_WLOCK; - ERR_FAIL_COND(!classes.has(p_class)); + ERR_FAIL_COND_MSG(!classes.has(p_class), "Request for nonexistent class '" + p_class + "'."); classes[p_class].disabled = !p_enable; } @@ -1319,7 +1319,7 @@ bool ClassDB::is_class_enabled(StringName p_class) { } } - ERR_FAIL_COND_V(!ti, false); + ERR_FAIL_COND_V_MSG(!ti, false, "Cannot get class '" + String(p_class) + "'."); return !ti->disabled; } @@ -1328,7 +1328,7 @@ bool ClassDB::is_class_exposed(StringName p_class) { OBJTYPE_RLOCK; ClassInfo *ti = classes.getptr(p_class); - ERR_FAIL_COND_V(!ti, false); + ERR_FAIL_COND_V_MSG(!ti, false, "Cannot get class '" + String(p_class) + "'."); return ti->exposed; } diff --git a/core/crypto/crypto.cpp b/core/crypto/crypto.cpp index 925a01b36a..83a25da901 100644 --- a/core/crypto/crypto.cpp +++ b/core/crypto/crypto.cpp @@ -149,7 +149,7 @@ Error ResourceFormatSaverCrypto::save(const String &p_path, const RES &p_resourc } else { ERR_FAIL_V(ERR_INVALID_PARAMETER); } - ERR_FAIL_COND_V(err != OK, err); + ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot save Crypto resource to file '" + p_path + "'."); return OK; } diff --git a/core/engine.cpp b/core/engine.cpp index 937439faaf..b9dc057257 100644 --- a/core/engine.cpp +++ b/core/engine.cpp @@ -38,7 +38,7 @@ void Engine::set_iterations_per_second(int p_ips) { - ERR_FAIL_COND(p_ips <= 0); + ERR_FAIL_COND_MSG(p_ips <= 0, "Engine iterations per second must be greater than 0."); ips = p_ips; } int Engine::get_iterations_per_second() const { diff --git a/core/hash_map.h b/core/hash_map.h index 81ddc376d0..38da1d59ab 100644 --- a/core/hash_map.h +++ b/core/hash_map.h @@ -112,7 +112,7 @@ private: void erase_hash_table() { - ERR_FAIL_COND(elements); + ERR_FAIL_COND_MSG(elements, "Cannot erase hash table if there are still elements inside."); memdelete_arr(hash_table); hash_table = 0; diff --git a/core/image.cpp b/core/image.cpp index 900efb0eb0..e0b0a1f8be 100644 --- a/core/image.cpp +++ b/core/image.cpp @@ -885,10 +885,10 @@ void Image::resize(int p_width, int p_height, Interpolation p_interpolation) { bool mipmap_aware = p_interpolation == INTERPOLATE_TRILINEAR /* || p_interpolation == INTERPOLATE_TRICUBIC */; - ERR_FAIL_COND(p_width <= 0); - ERR_FAIL_COND(p_height <= 0); - ERR_FAIL_COND(p_width > MAX_WIDTH); - ERR_FAIL_COND(p_height > MAX_HEIGHT); + ERR_FAIL_COND_MSG(p_width <= 0, "Image width cannot be greater than 0."); + ERR_FAIL_COND_MSG(p_height <= 0, "Image height cannot be greater than 0."); + ERR_FAIL_COND_MSG(p_width > MAX_WIDTH, "Image width cannot be greater than " + itos(MAX_WIDTH) + "."); + ERR_FAIL_COND_MSG(p_height > MAX_HEIGHT, "Image height cannot be greater than " + itos(MAX_HEIGHT) + "."); if (p_width == width && p_height == height) return; @@ -1096,12 +1096,12 @@ void Image::crop_from_point(int p_x, int p_y, int p_width, int p_height) { ERR_FAIL_COND_MSG(!_can_modify(format), "Cannot crop in compressed or custom image formats."); - ERR_FAIL_COND(p_x < 0); - ERR_FAIL_COND(p_y < 0); - ERR_FAIL_COND(p_width <= 0); - ERR_FAIL_COND(p_height <= 0); - ERR_FAIL_COND(p_x + p_width > MAX_WIDTH); - ERR_FAIL_COND(p_y + p_height > MAX_HEIGHT); + ERR_FAIL_COND_MSG(p_x < 0, "Start x position cannot be smaller than 0."); + ERR_FAIL_COND_MSG(p_y < 0, "Start y position cannot be smaller than 0."); + ERR_FAIL_COND_MSG(p_width <= 0, "Width of image must be greater than 0."); + ERR_FAIL_COND_MSG(p_height <= 0, "Height of image must be greater than 0."); + ERR_FAIL_COND_MSG(p_x + p_width > MAX_WIDTH, "End x position cannot be greater than " + itos(MAX_WIDTH) + "."); + ERR_FAIL_COND_MSG(p_y + p_height > MAX_HEIGHT, "End y position cannot be greater than " + itos(MAX_HEIGHT) + "."); /* to save memory, cropping should be done in-place, however, since this function will most likely either not be used much, or in critical areas, for now it won't, because @@ -2055,7 +2055,7 @@ Ref<Image> Image::get_rect(const Rect2 &p_area) const { void Image::blit_rect(const Ref<Image> &p_src, const Rect2 &p_src_rect, const Point2 &p_dest) { - ERR_FAIL_COND(p_src.is_null()); + ERR_FAIL_COND_MSG(p_src.is_null(), "It's not a reference to a valid Image object."); int dsize = data.size(); int srcdsize = p_src->data.size(); ERR_FAIL_COND(dsize == 0); @@ -2105,16 +2105,16 @@ void Image::blit_rect(const Ref<Image> &p_src, const Rect2 &p_src_rect, const Po void Image::blit_rect_mask(const Ref<Image> &p_src, const Ref<Image> &p_mask, const Rect2 &p_src_rect, const Point2 &p_dest) { - ERR_FAIL_COND(p_src.is_null()); - ERR_FAIL_COND(p_mask.is_null()); + ERR_FAIL_COND_MSG(p_src.is_null(), "It's not a reference to a valid Image object."); + ERR_FAIL_COND_MSG(p_mask.is_null(), "It's not a reference to a valid Image object."); int dsize = data.size(); int srcdsize = p_src->data.size(); int maskdsize = p_mask->data.size(); ERR_FAIL_COND(dsize == 0); ERR_FAIL_COND(srcdsize == 0); ERR_FAIL_COND(maskdsize == 0); - ERR_FAIL_COND(p_src->width != p_mask->width); - ERR_FAIL_COND(p_src->height != p_mask->height); + ERR_FAIL_COND_MSG(p_src->width != p_mask->width, "Source image width is different from mask width."); + ERR_FAIL_COND_MSG(p_src->height != p_mask->height, "Source image height is different from mask height."); ERR_FAIL_COND(format != p_src->format); Rect2i clipped_src_rect = Rect2i(0, 0, p_src->width, p_src->height).clip(p_src_rect); @@ -2168,7 +2168,7 @@ void Image::blit_rect_mask(const Ref<Image> &p_src, const Ref<Image> &p_mask, co void Image::blend_rect(const Ref<Image> &p_src, const Rect2 &p_src_rect, const Point2 &p_dest) { - ERR_FAIL_COND(p_src.is_null()); + ERR_FAIL_COND_MSG(p_src.is_null(), "It's not a reference to a valid Image object."); int dsize = data.size(); int srcdsize = p_src->data.size(); ERR_FAIL_COND(dsize == 0); @@ -2218,16 +2218,16 @@ void Image::blend_rect(const Ref<Image> &p_src, const Rect2 &p_src_rect, const P void Image::blend_rect_mask(const Ref<Image> &p_src, const Ref<Image> &p_mask, const Rect2 &p_src_rect, const Point2 &p_dest) { - ERR_FAIL_COND(p_src.is_null()); - ERR_FAIL_COND(p_mask.is_null()); + ERR_FAIL_COND_MSG(p_src.is_null(), "It's not a reference to a valid Image object."); + ERR_FAIL_COND_MSG(p_mask.is_null(), "It's not a reference to a valid Image object."); int dsize = data.size(); int srcdsize = p_src->data.size(); int maskdsize = p_mask->data.size(); ERR_FAIL_COND(dsize == 0); ERR_FAIL_COND(srcdsize == 0); ERR_FAIL_COND(maskdsize == 0); - ERR_FAIL_COND(p_src->width != p_mask->width); - ERR_FAIL_COND(p_src->height != p_mask->height); + ERR_FAIL_COND_MSG(p_src->width != p_mask->width, "Source image width is different from mask width."); + ERR_FAIL_COND_MSG(p_src->height != p_mask->height, "Source image height is different from mask height."); ERR_FAIL_COND(format != p_src->format); Rect2i clipped_src_rect = Rect2i(0, 0, p_src->width, p_src->height).clip(p_src_rect); diff --git a/core/image.h b/core/image.h index f29a30cda0..94ee8a2c33 100644 --- a/core/image.h +++ b/core/image.h @@ -356,7 +356,7 @@ public: void set_pixel(int p_x, int p_y, const Color &p_color); void copy_internals_from(const Ref<Image> &p_image) { - ERR_FAIL_COND(p_image.is_null()); + ERR_FAIL_COND_MSG(p_image.is_null(), "It's not a reference to a valid Image object."); format = p_image->format; width = p_image->width; height = p_image->height; diff --git a/core/input_map.cpp b/core/input_map.cpp index 2a8ac435fe..05c75febf2 100644 --- a/core/input_map.cpp +++ b/core/input_map.cpp @@ -56,7 +56,7 @@ void InputMap::_bind_methods() { void InputMap::add_action(const StringName &p_action, float p_deadzone) { - ERR_FAIL_COND(input_map.has(p_action)); + ERR_FAIL_COND_MSG(input_map.has(p_action), "InputMap already has action '" + String(p_action) + "'."); input_map[p_action] = Action(); static int last_id = 1; input_map[p_action].id = last_id; @@ -66,7 +66,7 @@ void InputMap::add_action(const StringName &p_action, float p_deadzone) { void InputMap::erase_action(const StringName &p_action) { - ERR_FAIL_COND(!input_map.has(p_action)); + ERR_FAIL_COND_MSG(!input_map.has(p_action), "Request for nonexistent InputMap action '" + String(p_action) + "'."); input_map.erase(p_action); } @@ -126,15 +126,15 @@ bool InputMap::has_action(const StringName &p_action) const { void InputMap::action_set_deadzone(const StringName &p_action, float p_deadzone) { - ERR_FAIL_COND(!input_map.has(p_action)); + ERR_FAIL_COND_MSG(!input_map.has(p_action), "Request for nonexistent InputMap action '" + String(p_action) + "'."); input_map[p_action].deadzone = p_deadzone; } void InputMap::action_add_event(const StringName &p_action, const Ref<InputEvent> &p_event) { - ERR_FAIL_COND(p_event.is_null()); - ERR_FAIL_COND(!input_map.has(p_action)); + ERR_FAIL_COND_MSG(p_event.is_null(), "It's not a reference to a valid InputEvent object."); + ERR_FAIL_COND_MSG(!input_map.has(p_action), "Request for nonexistent InputMap action '" + String(p_action) + "'."); if (_find_event(input_map[p_action], p_event)) return; //already gots @@ -143,13 +143,13 @@ void InputMap::action_add_event(const StringName &p_action, const Ref<InputEvent bool InputMap::action_has_event(const StringName &p_action, const Ref<InputEvent> &p_event) { - ERR_FAIL_COND_V(!input_map.has(p_action), false); + ERR_FAIL_COND_V_MSG(!input_map.has(p_action), false, "Request for nonexistent InputMap action '" + String(p_action) + "'."); return (_find_event(input_map[p_action], p_event) != NULL); } void InputMap::action_erase_event(const StringName &p_action, const Ref<InputEvent> &p_event) { - ERR_FAIL_COND(!input_map.has(p_action)); + ERR_FAIL_COND_MSG(!input_map.has(p_action), "Request for nonexistent InputMap action '" + String(p_action) + "'."); List<Ref<InputEvent> >::Element *E = _find_event(input_map[p_action], p_event); if (E) @@ -158,7 +158,7 @@ void InputMap::action_erase_event(const StringName &p_action, const Ref<InputEve void InputMap::action_erase_events(const StringName &p_action) { - ERR_FAIL_COND(!input_map.has(p_action)); + ERR_FAIL_COND_MSG(!input_map.has(p_action), "Request for nonexistent InputMap action '" + String(p_action) + "'."); input_map[p_action].inputs.clear(); } @@ -192,7 +192,7 @@ bool InputMap::event_is_action(const Ref<InputEvent> &p_event, const StringName bool InputMap::event_get_action_status(const Ref<InputEvent> &p_event, const StringName &p_action, bool *p_pressed, float *p_strength) const { Map<StringName, Action>::Element *E = input_map.find(p_action); - ERR_FAIL_COND_V_MSG(!E, false, "Request for nonexistent InputMap action: " + String(p_action) + "."); + ERR_FAIL_COND_V_MSG(!E, false, "Request for nonexistent InputMap action '" + String(p_action) + "'."); Ref<InputEventAction> input_event_action = p_event; if (input_event_action.is_valid()) { @@ -333,6 +333,6 @@ void InputMap::load_default() { InputMap::InputMap() { - ERR_FAIL_COND(singleton); + ERR_FAIL_COND_MSG(singleton, "Singleton in InputMap already exist."); singleton = this; } diff --git a/core/io/config_file.cpp b/core/io/config_file.cpp index 9063e028be..271e5c5a0b 100644 --- a/core/io/config_file.cpp +++ b/core/io/config_file.cpp @@ -111,7 +111,7 @@ void ConfigFile::get_sections(List<String> *r_sections) const { } void ConfigFile::get_section_keys(const String &p_section, List<String> *r_keys) const { - ERR_FAIL_COND(!values.has(p_section)); + ERR_FAIL_COND_MSG(!values.has(p_section), "Cannont get keys from nonexistent section '" + p_section + "'."); for (OrderedHashMap<String, Variant>::ConstElement E = values[p_section].front(); E; E = E.next()) { r_keys->push_back(E.key()); diff --git a/core/io/file_access_compressed.cpp b/core/io/file_access_compressed.cpp index 102cd9cf6c..a52c6f79c9 100644 --- a/core/io/file_access_compressed.cpp +++ b/core/io/file_access_compressed.cpp @@ -195,7 +195,7 @@ bool FileAccessCompressed::is_open() const { void FileAccessCompressed::seek(size_t p_position) { - ERR_FAIL_COND(!f); + ERR_FAIL_COND_MSG(!f, "File must be opened before use."); if (writing) { ERR_FAIL_COND(p_position > write_max); @@ -227,7 +227,7 @@ void FileAccessCompressed::seek(size_t p_position) { void FileAccessCompressed::seek_end(int64_t p_position) { - ERR_FAIL_COND(!f); + ERR_FAIL_COND_MSG(!f, "File must be opened before use."); if (writing) { seek(write_max + p_position); @@ -238,7 +238,7 @@ void FileAccessCompressed::seek_end(int64_t p_position) { } size_t FileAccessCompressed::get_position() const { - ERR_FAIL_COND_V(!f, 0); + ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); if (writing) { return write_pos; @@ -249,7 +249,7 @@ size_t FileAccessCompressed::get_position() const { } size_t FileAccessCompressed::get_len() const { - ERR_FAIL_COND_V(!f, 0); + ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); if (writing) { return write_max; @@ -260,7 +260,7 @@ size_t FileAccessCompressed::get_len() const { bool FileAccessCompressed::eof_reached() const { - ERR_FAIL_COND_V(!f, false); + ERR_FAIL_COND_V_MSG(!f, false, "File must be opened before use."); if (writing) { return false; } else { @@ -270,8 +270,8 @@ bool FileAccessCompressed::eof_reached() const { uint8_t FileAccessCompressed::get_8() const { - ERR_FAIL_COND_V(writing, 0); - ERR_FAIL_COND_V(!f, 0); + ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); + ERR_FAIL_COND_V_MSG(writing, 0, "File has not been opened in read mode."); if (at_end) { read_eof = true; @@ -301,8 +301,8 @@ uint8_t FileAccessCompressed::get_8() const { } int FileAccessCompressed::get_buffer(uint8_t *p_dst, int p_length) const { - ERR_FAIL_COND_V(writing, 0); - ERR_FAIL_COND_V(!f, 0); + ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); + ERR_FAIL_COND_V_MSG(writing, 0, "File has not been opened in read mode."); if (at_end) { read_eof = true; @@ -342,16 +342,16 @@ Error FileAccessCompressed::get_error() const { } void FileAccessCompressed::flush() { - ERR_FAIL_COND(!f); - ERR_FAIL_COND(!writing); + ERR_FAIL_COND_MSG(!f, "File must be opened before use."); + ERR_FAIL_COND_MSG(!writing, "File has not been opened in read mode."); // compressed files keep data in memory till close() } void FileAccessCompressed::store_8(uint8_t p_dest) { - ERR_FAIL_COND(!f); - ERR_FAIL_COND(!writing); + ERR_FAIL_COND_MSG(!f, "File must be opened before use."); + ERR_FAIL_COND_MSG(!writing, "File has not been opened in read mode."); WRITE_FIT(1); write_ptr[write_pos++] = p_dest; diff --git a/core/io/file_access_encrypted.cpp b/core/io/file_access_encrypted.cpp index 77decc107d..e45a873978 100644 --- a/core/io/file_access_encrypted.cpp +++ b/core/io/file_access_encrypted.cpp @@ -41,7 +41,7 @@ Error FileAccessEncrypted::open_and_parse(FileAccess *p_base, const Vector<uint8_t> &p_key, Mode p_mode) { - ERR_FAIL_COND_V(file != NULL, ERR_ALREADY_IN_USE); + ERR_FAIL_COND_V_MSG(file != NULL, ERR_ALREADY_IN_USE, "Can't open file while another file from path '" + file->get_path_absolute() + "' is open."); ERR_FAIL_COND_V(p_key.size() != 32, ERR_INVALID_PARAMETER); pos = 0; @@ -205,7 +205,7 @@ bool FileAccessEncrypted::eof_reached() const { uint8_t FileAccessEncrypted::get_8() const { - ERR_FAIL_COND_V(writing, 0); + ERR_FAIL_COND_V_MSG(writing, 0, "File has not been opened in read mode."); if (pos >= data.size()) { eofed = true; return 0; @@ -217,7 +217,7 @@ uint8_t FileAccessEncrypted::get_8() const { } int FileAccessEncrypted::get_buffer(uint8_t *p_dst, int p_length) const { - ERR_FAIL_COND_V(writing, 0); + ERR_FAIL_COND_V_MSG(writing, 0, "File has not been opened in read mode."); int to_copy = MIN(p_length, data.size() - pos); for (int i = 0; i < to_copy; i++) { @@ -239,7 +239,7 @@ Error FileAccessEncrypted::get_error() const { void FileAccessEncrypted::store_buffer(const uint8_t *p_src, int p_length) { - ERR_FAIL_COND(!writing); + ERR_FAIL_COND_MSG(!writing, "File has not been opened in read mode."); if (pos < data.size()) { @@ -259,14 +259,14 @@ void FileAccessEncrypted::store_buffer(const uint8_t *p_src, int p_length) { } void FileAccessEncrypted::flush() { - ERR_FAIL_COND(!writing); + ERR_FAIL_COND_MSG(!writing, "File has not been opened in read mode."); // encrypted files keep data in memory till close() } void FileAccessEncrypted::store_8(uint8_t p_dest) { - ERR_FAIL_COND(!writing); + ERR_FAIL_COND_MSG(!writing, "File has not been opened in read mode."); if (pos < data.size()) { data.write[pos] = p_dest; diff --git a/core/io/file_access_memory.cpp b/core/io/file_access_memory.cpp index fbcf5b8021..c0acd36751 100644 --- a/core/io/file_access_memory.cpp +++ b/core/io/file_access_memory.cpp @@ -90,7 +90,7 @@ Error FileAccessMemory::_open(const String &p_path, int p_mode_flags) { //name = DirAccess::normalize_path(name); Map<String, Vector<uint8_t> >::Element *E = files->find(name); - ERR_FAIL_COND_V(!E, ERR_FILE_NOT_FOUND); + ERR_FAIL_COND_V_MSG(!E, ERR_FILE_NOT_FOUND, "Can't find file '" + p_path + "'."); data = E->get().ptrw(); length = E->get().size(); diff --git a/core/io/file_access_network.cpp b/core/io/file_access_network.cpp index d1c7f5c334..e653a924ba 100644 --- a/core/io/file_access_network.cpp +++ b/core/io/file_access_network.cpp @@ -195,7 +195,7 @@ Error FileAccessNetworkClient::connect(const String &p_host, int p_port, const S DEBUG_PRINT("IP: " + String(ip) + " port " + itos(p_port)); Error err = client->connect_to_host(ip, p_port); - ERR_FAIL_COND_V(err, err); + ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot connect to host with IP: " + String(ip) + " and port: " + itos(p_port)); while (client->get_status() == StreamPeerTCP::STATUS_CONNECTING) { //DEBUG_PRINT("trying to connect...."); OS::get_singleton()->delay_usec(1000); @@ -339,7 +339,7 @@ bool FileAccessNetwork::is_open() const { void FileAccessNetwork::seek(size_t p_position) { - ERR_FAIL_COND(!opened); + ERR_FAIL_COND_MSG(!opened, "File must be opened before use."); eof_flag = p_position > total_size; if (p_position >= total_size) { @@ -355,18 +355,18 @@ void FileAccessNetwork::seek_end(int64_t p_position) { } size_t FileAccessNetwork::get_position() const { - ERR_FAIL_COND_V(!opened, 0); + ERR_FAIL_COND_V_MSG(!opened, 0, "File must be opened before use."); return pos; } size_t FileAccessNetwork::get_len() const { - ERR_FAIL_COND_V(!opened, 0); + ERR_FAIL_COND_V_MSG(!opened, 0, "File must be opened before use."); return total_size; } bool FileAccessNetwork::eof_reached() const { - ERR_FAIL_COND_V(!opened, false); + ERR_FAIL_COND_V_MSG(!opened, false, "File must be opened before use."); return eof_flag; } diff --git a/core/io/file_access_pack.cpp b/core/io/file_access_pack.cpp index d49d36c2b9..a4821e0ce8 100644 --- a/core/io/file_access_pack.cpp +++ b/core/io/file_access_pack.cpp @@ -321,7 +321,7 @@ FileAccessPack::FileAccessPack(const String &p_path, const PackedData::PackedFil pf(p_file), f(FileAccess::open(pf.pack, FileAccess::READ)) { - ERR_FAIL_COND_MSG(!f, "Can't open pack-referenced file: " + String(pf.pack) + "."); + ERR_FAIL_COND_MSG(!f, "Can't open pack-referenced file '" + String(pf.pack) + "'."); f->seek(pf.offset); pos = 0; diff --git a/core/io/file_access_zip.cpp b/core/io/file_access_zip.cpp index be28c9a877..083f56d92c 100644 --- a/core/io/file_access_zip.cpp +++ b/core/io/file_access_zip.cpp @@ -117,7 +117,7 @@ static void godot_free(voidpf opaque, voidpf address) { void ZipArchive::close_handle(unzFile p_file) const { - ERR_FAIL_COND(!p_file); + ERR_FAIL_COND_MSG(!p_file, "Cannot close a file if none is open."); FileAccess *f = (FileAccess *)unzGetOpaque(p_file); unzCloseCurrentFile(p_file); unzClose(p_file); @@ -126,11 +126,11 @@ void ZipArchive::close_handle(unzFile p_file) const { unzFile ZipArchive::get_file_handle(String p_file) const { - ERR_FAIL_COND_V(!file_exists(p_file), NULL); + ERR_FAIL_COND_V_MSG(!file_exists(p_file), NULL, "File '" + p_file + " doesn't exist."); File file = files[p_file]; FileAccess *f = FileAccess::open(packages[file.package].filename, FileAccess::READ); - ERR_FAIL_COND_V(!f, NULL); + ERR_FAIL_COND_V_MSG(!f, NULL, "Cannot open file '" + packages[file.package].filename + "'."); zlib_filefunc_def io; zeromem(&io, sizeof(io)); diff --git a/core/io/image_loader.cpp b/core/io/image_loader.cpp index a759e615c7..095c2abb54 100644 --- a/core/io/image_loader.cpp +++ b/core/io/image_loader.cpp @@ -46,14 +46,14 @@ bool ImageFormatLoader::recognize(const String &p_extension) const { } Error ImageLoader::load_image(String p_file, Ref<Image> p_image, FileAccess *p_custom, bool p_force_linear, float p_scale) { - ERR_FAIL_COND_V(p_image.is_null(), ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V_MSG(p_image.is_null(), ERR_INVALID_PARAMETER, "It's not a reference to a valid Image object."); FileAccess *f = p_custom; if (!f) { Error err; f = FileAccess::open(p_file, FileAccess::READ, &err); if (!f) { - ERR_PRINTS("Error opening file: " + p_file); + ERR_PRINTS("Error opening file '" + p_file + "'."); return err; } } diff --git a/core/io/ip.cpp b/core/io/ip.cpp index 3d87131b51..f1b6570799 100644 --- a/core/io/ip.cpp +++ b/core/io/ip.cpp @@ -305,7 +305,7 @@ IP *(*IP::_create)() = NULL; IP *IP::create() { - ERR_FAIL_COND_V(singleton, NULL); + ERR_FAIL_COND_V_MSG(singleton, NULL, "IP singleton already exist."); ERR_FAIL_COND_V(!_create, NULL); return _create(); } diff --git a/core/io/ip_address.cpp b/core/io/ip_address.cpp index df4be9b9fd..0980027f42 100644 --- a/core/io/ip_address.cpp +++ b/core/io/ip_address.cpp @@ -181,7 +181,7 @@ bool IP_Address::is_ipv4() const { } const uint8_t *IP_Address::get_ipv4() const { - ERR_FAIL_COND_V(!is_ipv4(), &(field8[12])); // Not the correct IPv4 (it's an IPv6), but we don't want to return a null pointer risking an engine crash. + ERR_FAIL_COND_V_MSG(!is_ipv4(), &(field8[12]), "IPv4 requested, but current IP is IPv6."); // Not the correct IPv4 (it's an IPv6), but we don't want to return a null pointer risking an engine crash. return &(field8[12]); } diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp index b386feb14c..2ae542bca7 100644 --- a/core/io/marshalls.cpp +++ b/core/io/marshalls.cpp @@ -478,7 +478,7 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int int used; Error err = decode_variant(key, buf, len, &used, p_allow_objects); - ERR_FAIL_COND_V(err, err); + ERR_FAIL_COND_V_MSG(err != OK, err, "Error when trying to decode Variant."); buf += used; len -= used; @@ -487,7 +487,7 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } err = decode_variant(value, buf, len, &used, p_allow_objects); - ERR_FAIL_COND_V(err, err); + ERR_FAIL_COND_V_MSG(err != OK, err, "Error when trying to decode Variant."); buf += used; len -= used; @@ -522,7 +522,7 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int int used = 0; Variant v; Error err = decode_variant(v, buf, len, &used, p_allow_objects); - ERR_FAIL_COND_V(err, err); + ERR_FAIL_COND_V_MSG(err != OK, err, "Error when trying to decode Variant."); buf += used; len -= used; varr.push_back(v); diff --git a/core/io/multiplayer_api.cpp b/core/io/multiplayer_api.cpp index ed6905c9a6..0ba84d0c8f 100644 --- a/core/io/multiplayer_api.cpp +++ b/core/io/multiplayer_api.cpp @@ -917,8 +917,7 @@ int MultiplayerAPI::_get_bandwidth_usage(const Vector<BandwidthFrame> &p_buffer, i = (i + p_buffer.size() - 1) % p_buffer.size(); } - ERR_EXPLAIN("Reached the end of the bandwidth profiler buffer, values might be inaccurate."); - ERR_FAIL_COND_V(i == p_pointer, total_bandwidth); + ERR_FAIL_COND_V_MSG(i == p_pointer, total_bandwidth, "Reached the end of the bandwidth profiler buffer, values might be inaccurate."); return total_bandwidth; } diff --git a/core/io/packet_peer.cpp b/core/io/packet_peer.cpp index 1c792c43d1..821a04ebad 100644 --- a/core/io/packet_peer.cpp +++ b/core/io/packet_peer.cpp @@ -101,9 +101,9 @@ Error PacketPeer::put_var(const Variant &p_packet, bool p_full_objects) { return OK; uint8_t *buf = (uint8_t *)alloca(len); - ERR_FAIL_COND_V(!buf, ERR_OUT_OF_MEMORY); + ERR_FAIL_COND_V_MSG(!buf, ERR_OUT_OF_MEMORY, "Out of memory."); err = encode_variant(p_packet, buf, len, p_full_objects || allow_object_decoding); - ERR_FAIL_COND_V(err, err); + ERR_FAIL_COND_V_MSG(err != OK, err, "Error when trying to encode Variant."); return put_packet(buf, len); } @@ -150,7 +150,7 @@ void PacketPeer::_bind_methods() { void PacketPeerStream::_set_stream_peer(REF p_peer) { - ERR_FAIL_COND(p_peer.is_null()); + ERR_FAIL_COND_MSG(p_peer.is_null(), "It's not a reference to a valid Resource object."); set_stream_peer(p_peer); } diff --git a/core/io/pck_packer.cpp b/core/io/pck_packer.cpp index 1c89bc6268..443f390bb7 100644 --- a/core/io/pck_packer.cpp +++ b/core/io/pck_packer.cpp @@ -107,7 +107,7 @@ Error PCKPacker::add_file(const String &p_file, const String &p_src) { Error PCKPacker::flush(bool p_verbose) { - ERR_FAIL_COND_V(!file, ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V_MSG(!file, ERR_INVALID_PARAMETER, "File must be opened before use."); // write the index diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index 0ad2479b05..e91dd579b5 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -378,10 +378,10 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { for (uint32_t i = 0; i < len; i++) { Variant key; Error err = parse_variant(key); - ERR_FAIL_COND_V(err, ERR_FILE_CORRUPT); + ERR_FAIL_COND_V_MSG(err, ERR_FILE_CORRUPT, "Error when trying to parse Variant."); Variant value; err = parse_variant(value); - ERR_FAIL_COND_V(err, ERR_FILE_CORRUPT); + ERR_FAIL_COND_V_MSG(err, ERR_FILE_CORRUPT, "Error when trying to parse Variant."); d[key] = value; } r_v = d; @@ -395,7 +395,7 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { for (uint32_t i = 0; i < len; i++) { Variant val; Error err = parse_variant(val); - ERR_FAIL_COND_V(err, ERR_FILE_CORRUPT); + ERR_FAIL_COND_V_MSG(err, ERR_FILE_CORRUPT, "Error when trying to parse Variant."); a[i] = val; } r_v = a; @@ -983,7 +983,7 @@ Ref<ResourceInteractiveLoader> ResourceFormatLoaderBinary::load_interactive(cons Error err; FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err); - ERR_FAIL_COND_V(err != OK, Ref<ResourceInteractiveLoader>()); + ERR_FAIL_COND_V_MSG(err != OK, Ref<ResourceInteractiveLoader>(), "Cannot open file '" + p_path + "'."); Ref<ResourceInteractiveLoaderBinary> ria = memnew(ResourceInteractiveLoaderBinary); String path = p_original_path != "" ? p_original_path : p_path; @@ -1032,7 +1032,7 @@ bool ResourceFormatLoaderBinary::handles_type(const String &p_type) const { void ResourceFormatLoaderBinary::get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types) { FileAccess *f = FileAccess::open(p_path, FileAccess::READ); - ERR_FAIL_COND(!f); + ERR_FAIL_COND_MSG(!f, "Cannot open file '" + p_path + "'."); Ref<ResourceInteractiveLoaderBinary> ria = memnew(ResourceInteractiveLoaderBinary); ria->local_path = ProjectSettings::get_singleton()->localize_path(p_path); @@ -1046,7 +1046,7 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons //Error error=OK; FileAccess *f = FileAccess::open(p_path, FileAccess::READ); - ERR_FAIL_COND_V(!f, ERR_CANT_OPEN); + ERR_FAIL_COND_V_MSG(!f, ERR_CANT_OPEN, "Cannot open file '" + p_path + "'."); FileAccess *fw = NULL; //=FileAccess::open(p_path+".depren"); @@ -1066,7 +1066,7 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons if (err) { memdelete(fac); memdelete(facw); - ERR_FAIL_COND_V(err, ERR_FILE_CORRUPT); + ERR_FAIL_COND_V_MSG(err, ERR_FILE_CORRUPT, "Cannot create file '" + p_path + ".depren'."); } fw = facw; @@ -1076,13 +1076,13 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons //error=ERR_FILE_UNRECOGNIZED; memdelete(f); - ERR_FAIL_V_MSG(ERR_FILE_UNRECOGNIZED, "Unrecognized binary resource file: " + local_path + "."); + ERR_FAIL_V_MSG(ERR_FILE_UNRECOGNIZED, "Unrecognized binary resource file '" + local_path + "'."); } else { fw = FileAccess::open(p_path + ".depren", FileAccess::WRITE); if (!fw) { memdelete(f); } - ERR_FAIL_COND_V(!fw, ERR_CANT_CREATE); + ERR_FAIL_COND_V_MSG(!fw, ERR_CANT_CREATE, "Cannot create file '" + p_path + ".depren'."); uint8_t magic[4] = { 'R', 'S', 'R', 'C' }; fw->store_buffer(magic, 4); @@ -1113,12 +1113,12 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons memdelete(da); //use the old approach - WARN_PRINTS("This file is old, so it can't refactor dependencies, opening and resaving: " + p_path + "."); + WARN_PRINTS("This file is old, so it can't refactor dependencies, opening and resaving '" + p_path + "'."); Error err; f = FileAccess::open(p_path, FileAccess::READ, &err); - ERR_FAIL_COND_V(err != OK, ERR_FILE_CANT_OPEN); + ERR_FAIL_COND_V_MSG(err != OK, ERR_FILE_CANT_OPEN, "Cannot open file '" + p_path + "'."); Ref<ResourceInteractiveLoaderBinary> ria = memnew(ResourceInteractiveLoaderBinary); ria->local_path = ProjectSettings::get_singleton()->localize_path(p_path); @@ -1751,7 +1751,7 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p f = FileAccess::open(p_path, FileAccess::WRITE, &err); } - ERR_FAIL_COND_V(err, err); + ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot create file '" + p_path + "'."); relative_paths = p_flags & ResourceSaver::FLAG_RELATIVE_PATHS; skip_editor = p_flags & ResourceSaver::FLAG_OMIT_EDITOR_PROPERTIES; diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index 9e954890bc..f3eba44973 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -205,7 +205,7 @@ RES ResourceFormatLoader::load(const String &p_path, const String &p_original_pa if (r_error) *r_error = err; - ERR_FAIL_COND_V(err != OK, RES()); + ERR_FAIL_COND_V_MSG(err != OK, RES(), "Failed to load resource '" + p_path + "'."); } } diff --git a/core/io/resource_saver.cpp b/core/io/resource_saver.cpp index a9ad62afe6..7aa8732366 100644 --- a/core/io/resource_saver.cpp +++ b/core/io/resource_saver.cpp @@ -158,7 +158,7 @@ void ResourceSaver::get_recognized_extensions(const RES &p_resource, List<String void ResourceSaver::add_resource_format_saver(Ref<ResourceFormatSaver> p_format_saver, bool p_at_front) { - ERR_FAIL_COND(p_format_saver.is_null()); + ERR_FAIL_COND_MSG(p_format_saver.is_null(), "It's not a reference to a valid ResourceFormatSaver object."); ERR_FAIL_COND(saver_count >= MAX_SAVERS); if (p_at_front) { @@ -174,7 +174,7 @@ void ResourceSaver::add_resource_format_saver(Ref<ResourceFormatSaver> p_format_ void ResourceSaver::remove_resource_format_saver(Ref<ResourceFormatSaver> p_format_saver) { - ERR_FAIL_COND(p_format_saver.is_null()); + ERR_FAIL_COND_MSG(p_format_saver.is_null(), "It's not a reference to a valid ResourceFormatSaver object."); // Find saver int i = 0; diff --git a/core/io/stream_peer.cpp b/core/io/stream_peer.cpp index 84b8554d54..f19e055b64 100644 --- a/core/io/stream_peer.cpp +++ b/core/io/stream_peer.cpp @@ -370,7 +370,7 @@ Variant StreamPeer::get_var(bool p_allow_objects) { Variant ret; err = decode_variant(ret, var.ptr(), len, NULL, p_allow_objects); - ERR_FAIL_COND_V(err != OK, Variant()); + ERR_FAIL_COND_V_MSG(err != OK, Variant(), "Error when trying to decode Variant."); return ret; } diff --git a/core/io/translation_loader_po.cpp b/core/io/translation_loader_po.cpp index e8e71c10ca..9b6888ac21 100644 --- a/core/io/translation_loader_po.cpp +++ b/core/io/translation_loader_po.cpp @@ -182,7 +182,7 @@ RES TranslationLoaderPO::load(const String &p_path, const String &p_original_pat *r_error = ERR_CANT_OPEN; FileAccess *f = FileAccess::open(p_path, FileAccess::READ); - ERR_FAIL_COND_V(!f, RES()); + ERR_FAIL_COND_V_MSG(!f, RES(), "Cannot open file '" + p_path + "'."); return load_translation(f, r_error); } diff --git a/core/io/xml_parser.cpp b/core/io/xml_parser.cpp index 9487947365..575c78734f 100644 --- a/core/io/xml_parser.cpp +++ b/core/io/xml_parser.cpp @@ -484,7 +484,7 @@ Error XMLParser::open(const String &p_path) { Error err; FileAccess *file = FileAccess::open(p_path, FileAccess::READ, &err); - ERR_FAIL_COND_V(err != OK, err); + ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot open file '" + p_path + "'."); length = file->get_len(); ERR_FAIL_COND_V(length < 1, ERR_FILE_CORRUPT); diff --git a/core/math/basis.cpp b/core/math/basis.cpp index 2985959113..0a491010e2 100644 --- a/core/math/basis.cpp +++ b/core/math/basis.cpp @@ -807,7 +807,7 @@ void Basis::set_quat(const Quat &p_quat) { void Basis::set_axis_angle(const Vector3 &p_axis, real_t p_phi) { // Rotation matrix from axis and angle, see https://en.wikipedia.org/wiki/Rotation_matrix#Rotation_matrix_from_axis_angle #ifdef MATH_CHECKS - ERR_FAIL_COND(!p_axis.is_normalized()); + ERR_FAIL_COND_MSG(!p_axis.is_normalized(), "Axis must be normalized."); #endif Vector3 axis_sq(p_axis.x * p_axis.x, p_axis.y * p_axis.y, p_axis.z * p_axis.z); real_t cosine = Math::cos(p_phi); diff --git a/core/math/geometry.cpp b/core/math/geometry.cpp index f37db90929..30cb736d68 100644 --- a/core/math/geometry.cpp +++ b/core/math/geometry.cpp @@ -241,10 +241,7 @@ PoolVector<PoolVector<Face3> > Geometry::separate_objects(PoolVector<Face3> p_ar bool error = _connect_faces(_fcptr, len, -1); - if (error) { - - ERR_FAIL_COND_V(error, PoolVector<PoolVector<Face3> >()); // Invalid geometry. - } + ERR_FAIL_COND_V_MSG(error, PoolVector<PoolVector<Face3> >(), "Invalid geometry."); // Group connected faces in separate objects. diff --git a/core/message_queue.cpp b/core/message_queue.cpp index 390989ac91..a76b5167b6 100644 --- a/core/message_queue.cpp +++ b/core/message_queue.cpp @@ -340,7 +340,7 @@ bool MessageQueue::is_flushing() const { MessageQueue::MessageQueue() { - ERR_FAIL_COND(singleton != NULL); + ERR_FAIL_COND_MSG(singleton != NULL, "MessageQueue singleton already exist."); singleton = this; flushing = false; diff --git a/core/node_path.cpp b/core/node_path.cpp index 8244785d84..b43f76f680 100644 --- a/core/node_path.cpp +++ b/core/node_path.cpp @@ -375,7 +375,7 @@ NodePath::NodePath(const String &p_path) { if (str == "") { if (path[i] == 0) continue; // Allow end-of-path : - ERR_FAIL_MSG("Invalid NodePath: " + p_path + "."); + ERR_FAIL_MSG("Invalid NodePath '" + p_path + "'."); } subpath.push_back(str); diff --git a/core/object.cpp b/core/object.cpp index 62bfa31480..6facf38733 100644 --- a/core/object.cpp +++ b/core/object.cpp @@ -1100,9 +1100,9 @@ void Object::get_meta_list(List<String> *p_list) const { void Object::add_user_signal(const MethodInfo &p_signal) { - ERR_FAIL_COND(p_signal.name == ""); - ERR_FAIL_COND(ClassDB::has_signal(get_class_name(), p_signal.name)); - ERR_FAIL_COND(signal_map.has(p_signal.name)); + ERR_FAIL_COND_MSG(p_signal.name == "", "Signal name cannot be empty."); + ERR_FAIL_COND_MSG(ClassDB::has_signal(get_class_name(), p_signal.name), "User signal's name conflicts with a built-in signal of '" + get_class_name() + "'."); + ERR_FAIL_COND_MSG(signal_map.has(p_signal.name), "Trying to add already existing signal '" + p_signal.name + "'."); Signal s; s.user = p_signal; signal_map[p_signal.name] = s; diff --git a/core/os/dir_access.cpp b/core/os/dir_access.cpp index b444f0ae1e..e7496055ec 100644 --- a/core/os/dir_access.cpp +++ b/core/os/dir_access.cpp @@ -244,7 +244,7 @@ DirAccess *DirAccess::open(const String &p_path, Error *r_error) { DirAccess *da = create_for_path(p_path); - ERR_FAIL_COND_V(!da, NULL); + ERR_FAIL_COND_V_MSG(!da, NULL, "Cannot create DirAccess for path '" + p_path + "'."); Error err = da->change_dir(p_path); if (r_error) *r_error = err; @@ -384,39 +384,36 @@ Error DirAccess::_copy_dir(DirAccess *p_target_da, String p_to, int p_chmod_flag String target_dir = p_to + rel_path; if (!p_target_da->dir_exists(target_dir)) { Error err = p_target_da->make_dir(target_dir); - ERR_FAIL_COND_V(err, err); + ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot create directory '" + target_dir + "'."); } Error err = change_dir(E->get()); - ERR_FAIL_COND_V(err, err); + ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot change current directory to '" + E->get() + "'."); + err = _copy_dir(p_target_da, p_to + rel_path + "/", p_chmod_flags); if (err) { change_dir(".."); - ERR_PRINT("Failed to copy recursively"); - return err; + ERR_FAIL_V_MSG(err, "Failed to copy recursively."); } err = change_dir(".."); - if (err) { - ERR_PRINT("Failed to go back"); - return err; - } + ERR_FAIL_COND_V_MSG(err != OK, err, "Failed to go back."); } return OK; } Error DirAccess::copy_dir(String p_from, String p_to, int p_chmod_flags) { - ERR_FAIL_COND_V(!dir_exists(p_from), ERR_FILE_NOT_FOUND); + ERR_FAIL_COND_V_MSG(!dir_exists(p_from), ERR_FILE_NOT_FOUND, "Source directory doesn't exist."); DirAccess *target_da = DirAccess::create_for_path(p_to); - ERR_FAIL_COND_V(!target_da, ERR_CANT_CREATE); + ERR_FAIL_COND_V_MSG(!target_da, ERR_CANT_CREATE, "Cannot create DirAccess for path '" + p_to + "'."); if (!target_da->dir_exists(p_to)) { Error err = target_da->make_dir_recursive(p_to); if (err) { memdelete(target_da); } - ERR_FAIL_COND_V(err, err); + ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot create directory '" + p_to + "'."); } if (!p_to.ends_with("/")) { diff --git a/core/os/file_access.cpp b/core/os/file_access.cpp index 9a8315a3bb..738e597730 100644 --- a/core/os/file_access.cpp +++ b/core/os/file_access.cpp @@ -498,7 +498,7 @@ uint64_t FileAccess::get_modified_time(const String &p_file) { return 0; FileAccess *fa = create_for_path(p_file); - ERR_FAIL_COND_V(!fa, 0); + ERR_FAIL_COND_V_MSG(!fa, 0, "Cannot create FileAccess for path '" + p_file + "'."); uint64_t mt = fa->_get_modified_time(p_file); memdelete(fa); @@ -511,7 +511,7 @@ uint32_t FileAccess::get_unix_permissions(const String &p_file) { return 0; FileAccess *fa = create_for_path(p_file); - ERR_FAIL_COND_V(!fa, 0); + ERR_FAIL_COND_V_MSG(!fa, 0, "Cannot create FileAccess for path '" + p_file + "'."); uint32_t mt = fa->_get_unix_permissions(p_file); memdelete(fa); @@ -521,7 +521,7 @@ uint32_t FileAccess::get_unix_permissions(const String &p_file) { Error FileAccess::set_unix_permissions(const String &p_file, uint32_t p_permissions) { FileAccess *fa = create_for_path(p_file); - ERR_FAIL_COND_V(!fa, ERR_CANT_CREATE); + ERR_FAIL_COND_V_MSG(!fa, ERR_CANT_CREATE, "Cannot create FileAccess for path '" + p_file + "'."); Error err = fa->_set_unix_permissions(p_file, p_permissions); memdelete(fa); @@ -599,7 +599,7 @@ Vector<uint8_t> FileAccess::get_file_as_array(const String &p_path, Error *r_err if (r_error) { // if error requested, do not throw error return Vector<uint8_t>(); } - ERR_FAIL_V_MSG(Vector<uint8_t>(), "Can't open file from path: " + String(p_path) + "."); + ERR_FAIL_V_MSG(Vector<uint8_t>(), "Can't open file from path '" + String(p_path) + "'."); } Vector<uint8_t> data; data.resize(f->get_len()); @@ -619,7 +619,7 @@ String FileAccess::get_file_as_string(const String &p_path, Error *r_error) { if (r_error) { return String(); } - ERR_FAIL_V_MSG(String(), "Can't get file as string from path: " + String(p_path) + "."); + ERR_FAIL_V_MSG(String(), "Can't get file as string from path '" + String(p_path) + "'."); } String ret; diff --git a/core/os/os.cpp b/core/os/os.cpp index 7531900480..b44487b908 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -722,7 +722,7 @@ int OS::get_audio_driver_count() const { const char *OS::get_audio_driver_name(int p_driver) const { AudioDriver *driver = AudioDriverManager::get_driver(p_driver); - ERR_FAIL_COND_V(!driver, ""); + ERR_FAIL_COND_V_MSG(!driver, "", "Cannot get audio driver at index '" + itos(p_driver) + "'."); return AudioDriverManager::get_driver(p_driver)->get_name(); } diff --git a/core/packed_data_container.cpp b/core/packed_data_container.cpp index 54bf12b314..003e7e7428 100644 --- a/core/packed_data_container.cpp +++ b/core/packed_data_container.cpp @@ -119,7 +119,7 @@ Variant PackedDataContainer::_get_at_ofs(uint32_t p_ofs, const uint8_t *p_buf, b if (rerr != OK) { err = true; - ERR_FAIL_COND_V(err != OK, Variant()); + ERR_FAIL_COND_V_MSG(err != OK, Variant(), "Error when trying to decode Variant."); } return v; } diff --git a/core/pool_vector.h b/core/pool_vector.h index 957a72483c..fbd4d630be 100644 --- a/core/pool_vector.h +++ b/core/pool_vector.h @@ -508,7 +508,7 @@ T PoolVector<T>::operator[](int p_index) const { template <class T> Error PoolVector<T>::resize(int p_size) { - ERR_FAIL_COND_V(p_size < 0, ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V_MSG(p_size < 0, ERR_INVALID_PARAMETER, "Size of PoolVector cannot be negative."); if (alloc == NULL) { @@ -536,7 +536,7 @@ Error PoolVector<T>::resize(int p_size) { } else { - ERR_FAIL_COND_V(alloc->lock > 0, ERR_LOCKED); //can't resize if locked! + ERR_FAIL_COND_V_MSG(alloc->lock > 0, ERR_LOCKED, "Can't resize PoolVector if locked."); //can't resize if locked! } size_t new_size = sizeof(T) * p_size; diff --git a/core/project_settings.cpp b/core/project_settings.cpp index ec2c5ecbb3..9e3b9bd1e4 100644 --- a/core/project_settings.cpp +++ b/core/project_settings.cpp @@ -113,12 +113,12 @@ String ProjectSettings::localize_path(const String &p_path) const { void ProjectSettings::set_initial_value(const String &p_name, const Variant &p_value) { - ERR_FAIL_COND(!props.has(p_name)); + ERR_FAIL_COND_MSG(!props.has(p_name), "Request for nonexistent project setting: " + p_name + "."); props[p_name].initial = p_value; } void ProjectSettings::set_restart_if_changed(const String &p_name, bool p_restart) { - ERR_FAIL_COND(!props.has(p_name)); + ERR_FAIL_COND_MSG(!props.has(p_name), "Request for nonexistent project setting: " + p_name + "."); props[p_name].restart_if_changed = p_restart; } @@ -336,7 +336,7 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b if (p_main_pack != "") { bool ok = _load_resource_pack(p_main_pack); - ERR_FAIL_COND_V(!ok, ERR_CANT_OPEN); + ERR_FAIL_COND_V_MSG(!ok, ERR_CANT_OPEN, "Cannot open resource pack '" + p_main_pack + "'."); Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary"); if (err == OK) { @@ -421,7 +421,7 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b // or, if requested (`p_upwards`) in parent directories. DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); - ERR_FAIL_COND_V(!d, ERR_CANT_CREATE); + ERR_FAIL_COND_V_MSG(!d, ERR_CANT_CREATE, "Cannot create DirAccess for path '" + p_path + "'."); d->change_dir(p_path); String current_dir = d->get_current_dir(); @@ -609,19 +609,19 @@ Error ProjectSettings::_load_settings_text_or_binary(const String &p_text_path, int ProjectSettings::get_order(const String &p_name) const { - ERR_FAIL_COND_V(!props.has(p_name), -1); + ERR_FAIL_COND_V_MSG(!props.has(p_name), -1, "Request for nonexistent project setting: " + p_name + "."); return props[p_name].order; } void ProjectSettings::set_order(const String &p_name, int p_order) { - ERR_FAIL_COND(!props.has(p_name)); + ERR_FAIL_COND_MSG(!props.has(p_name), "Request for nonexistent project setting: " + p_name + "."); props[p_name].order = p_order; } void ProjectSettings::set_builtin_order(const String &p_name) { - ERR_FAIL_COND(!props.has(p_name)); + ERR_FAIL_COND_MSG(!props.has(p_name), "Request for nonexistent project setting: " + p_name + "."); if (props[p_name].order >= NO_BUILTIN_ORDER_BASE) { props[p_name].order = last_builtin_order++; } @@ -629,7 +629,7 @@ void ProjectSettings::set_builtin_order(const String &p_name) { void ProjectSettings::clear(const String &p_name) { - ERR_FAIL_COND(!props.has(p_name)); + ERR_FAIL_COND_MSG(!props.has(p_name), "Request for nonexistent project setting: " + p_name + "."); props.erase(p_name); } @@ -706,7 +706,7 @@ Error ProjectSettings::_save_settings_binary(const String &p_file, const Map<Str err = encode_variant(value, NULL, len, true); if (err != OK) memdelete(file); - ERR_FAIL_COND_V(err != OK, ERR_INVALID_DATA); + ERR_FAIL_COND_V_MSG(err != OK, ERR_INVALID_DATA, "Error when trying to encode Variant."); Vector<uint8_t> buff; buff.resize(len); @@ -714,7 +714,7 @@ Error ProjectSettings::_save_settings_binary(const String &p_file, const Map<Str err = encode_variant(value, buff.ptrw(), len, true); if (err != OK) memdelete(file); - ERR_FAIL_COND_V(err != OK, ERR_INVALID_DATA); + ERR_FAIL_COND_V_MSG(err != OK, ERR_INVALID_DATA, "Error when trying to encode Variant."); file->store_32(len); file->store_buffer(buff.ptr(), buff.size()); } @@ -787,7 +787,7 @@ Error ProjectSettings::_save_custom_bnd(const String &p_file) { // add other par Error ProjectSettings::save_custom(const String &p_path, const CustomMap &p_custom, const Vector<String> &p_custom_features, bool p_merge_with_current) { - ERR_FAIL_COND_V(p_path == "", ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V_MSG(p_path == "", ERR_INVALID_PARAMETER, "Project settings save path cannot be empty."); Set<_VCSort> vclist; diff --git a/core/resource.cpp b/core/resource.cpp index 5a5efa4644..87c92ca5b1 100644 --- a/core/resource.cpp +++ b/core/resource.cpp @@ -75,7 +75,7 @@ void Resource::set_path(const String &p_path, bool p_take_over) { bool exists = ResourceCache::resources.has(p_path); ResourceCache::lock->read_unlock(); - ERR_FAIL_COND_MSG(exists, "Another resource is loaded from path: " + p_path + " (possible cyclic resource inclusion)."); + ERR_FAIL_COND_MSG(exists, "Another resource is loaded from path '" + p_path + "' (possible cyclic resource inclusion)."); } } path_cache = p_path; @@ -509,7 +509,7 @@ void ResourceCache::dump(const char *p_file, bool p_short) { FileAccess *f = NULL; if (p_file) { f = FileAccess::open(p_file, FileAccess::WRITE); - ERR_FAIL_COND(!f); + ERR_FAIL_COND_MSG(!f, "Cannot create file at path '" + String(p_file) + "'."); } const String *K = NULL; diff --git a/drivers/dummy/rasterizer_dummy.h b/drivers/dummy/rasterizer_dummy.h index 3deaef09e7..8d5cf2ebea 100644 --- a/drivers/dummy/rasterizer_dummy.h +++ b/drivers/dummy/rasterizer_dummy.h @@ -181,8 +181,8 @@ public: DummyTexture *t = texture_owner.get(p_texture); ERR_FAIL_COND(!t); + ERR_FAIL_COND_MSG(p_image.is_null(), "It's not a reference to a valid Image object."); ERR_FAIL_COND(t->format != p_image->get_format()); - ERR_FAIL_COND(p_image.is_null()); ERR_FAIL_COND(src_w <= 0 || src_h <= 0); ERR_FAIL_COND(src_x < 0 || src_y < 0 || src_x + src_w > p_image->get_width() || src_y + src_h > p_image->get_height()); ERR_FAIL_COND(dst_x < 0 || dst_y < 0 || dst_x + src_w > t->width || dst_y + src_h > t->height); diff --git a/drivers/unix/file_access_unix.cpp b/drivers/unix/file_access_unix.cpp index 071734eb48..8be1d5d8f3 100644 --- a/drivers/unix/file_access_unix.cpp +++ b/drivers/unix/file_access_unix.cpp @@ -58,7 +58,7 @@ void FileAccessUnix::check_errors() const { - ERR_FAIL_COND(!f); + ERR_FAIL_COND_MSG(!f, "File must be opened before use."); if (feof(f)) { @@ -76,7 +76,7 @@ Error FileAccessUnix::_open(const String &p_path, int p_mode_flags) { path = fix_path(p_path); //printf("opening %ls, %i\n", path.c_str(), Memory::get_static_mem_usage()); - ERR_FAIL_COND_V(f, ERR_ALREADY_IN_USE); + ERR_FAIL_COND_V_MSG(f, ERR_ALREADY_IN_USE, "File is already in use."); const char *mode_string; if (p_mode_flags == READ) @@ -171,7 +171,7 @@ String FileAccessUnix::get_path_absolute() const { void FileAccessUnix::seek(size_t p_position) { - ERR_FAIL_COND(!f); + ERR_FAIL_COND_MSG(!f, "File must be opened before use."); last_error = OK; if (fseek(f, p_position, SEEK_SET)) @@ -180,7 +180,7 @@ void FileAccessUnix::seek(size_t p_position) { void FileAccessUnix::seek_end(int64_t p_position) { - ERR_FAIL_COND(!f); + ERR_FAIL_COND_MSG(!f, "File must be opened before use."); if (fseek(f, p_position, SEEK_END)) check_errors(); @@ -188,7 +188,7 @@ void FileAccessUnix::seek_end(int64_t p_position) { size_t FileAccessUnix::get_position() const { - ERR_FAIL_COND_V(!f, 0); + ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); long pos = ftell(f); if (pos < 0) { @@ -200,7 +200,7 @@ size_t FileAccessUnix::get_position() const { size_t FileAccessUnix::get_len() const { - ERR_FAIL_COND_V(!f, 0); + ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); long pos = ftell(f); ERR_FAIL_COND_V(pos < 0, 0); @@ -219,7 +219,7 @@ bool FileAccessUnix::eof_reached() const { uint8_t FileAccessUnix::get_8() const { - ERR_FAIL_COND_V(!f, 0); + ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); uint8_t b; if (fread(&b, 1, 1, f) == 0) { check_errors(); @@ -230,7 +230,7 @@ uint8_t FileAccessUnix::get_8() const { int FileAccessUnix::get_buffer(uint8_t *p_dst, int p_length) const { - ERR_FAIL_COND_V(!f, -1); + ERR_FAIL_COND_V_MSG(!f, -1, "File must be opened before use."); int read = fread(p_dst, 1, p_length, f); check_errors(); return read; @@ -243,18 +243,19 @@ Error FileAccessUnix::get_error() const { void FileAccessUnix::flush() { - ERR_FAIL_COND(!f); + ERR_FAIL_COND_MSG(!f, "File must be opened before use."); fflush(f); } void FileAccessUnix::store_8(uint8_t p_dest) { - ERR_FAIL_COND(!f); + ERR_FAIL_COND_MSG(!f, "File must be opened before use."); ERR_FAIL_COND(fwrite(&p_dest, 1, 1, f) != 1); } void FileAccessUnix::store_buffer(const uint8_t *p_src, int p_length) { - ERR_FAIL_COND(!f); + + ERR_FAIL_COND_MSG(!f, "File must be opened before use."); ERR_FAIL_COND((int)fwrite(p_src, 1, p_length, f) != p_length); } diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp index ab5590dba4..bc57c0b8df 100644 --- a/drivers/unix/os_unix.cpp +++ b/drivers/unix/os_unix.cpp @@ -298,7 +298,7 @@ Error OS_Unix::execute(const String &p_path, const List<String> &p_arguments, bo } FILE *f = popen(argss.utf8().get_data(), "r"); - ERR_FAIL_COND_V(!f, ERR_CANT_OPEN); + ERR_FAIL_COND_V_MSG(!f, ERR_CANT_OPEN, "Cannot pipe stream from process running with following arguments '" + argss + "'."); char buf[65535]; diff --git a/editor/collada/collada.cpp b/editor/collada/collada.cpp index 1bb49a4167..d2ecf0f7f3 100644 --- a/editor/collada/collada.cpp +++ b/editor/collada/collada.cpp @@ -2514,7 +2514,7 @@ Error Collada::load(const String &p_path, int p_flags) { Ref<XMLParser> parserr = memnew(XMLParser); XMLParser &parser = *parserr.ptr(); Error err = parser.open(p_path); - ERR_FAIL_COND_V(err, err); + ERR_FAIL_COND_V_MSG(err, err, "Cannot open Collada file '" + p_path + "'."); state.local_path = ProjectSettings::get_singleton()->localize_path(p_path); state.import_flags = p_flags; @@ -2530,7 +2530,7 @@ Error Collada::load(const String &p_path, int p_flags) { } } - ERR_FAIL_COND_V(err != OK, ERR_FILE_CORRUPT); + ERR_FAIL_COND_V_MSG(err != OK, ERR_FILE_CORRUPT, "Corrupted Collada file '" + p_path + "'."); /* Start loading Collada */ diff --git a/editor/editor_data.cpp b/editor/editor_data.cpp index c98635d16b..777eda2170 100644 --- a/editor/editor_data.cpp +++ b/editor/editor_data.cpp @@ -481,7 +481,7 @@ EditorPlugin *EditorData::get_editor_plugin(int p_idx) { void EditorData::add_custom_type(const String &p_type, const String &p_inherits, const Ref<Script> &p_script, const Ref<Texture> &p_icon) { - ERR_FAIL_COND(p_script.is_null()); + ERR_FAIL_COND_MSG(p_script.is_null(), "It's not a reference to a valid Script object."); CustomType ct; ct.name = p_type; ct.icon = p_icon; diff --git a/editor/editor_dir_dialog.cpp b/editor/editor_dir_dialog.cpp index 7733ecb9da..0636ae3aea 100644 --- a/editor/editor_dir_dialog.cpp +++ b/editor/editor_dir_dialog.cpp @@ -151,7 +151,7 @@ void EditorDirDialog::_make_dir_confirm() { String dir = ti->get_metadata(0); DirAccessRef d = DirAccess::open(dir); - ERR_FAIL_COND(!d); + ERR_FAIL_COND_MSG(!d, "Cannot open directory '" + dir + "'."); Error err = d->make_dir(makedirname->get_text()); if (err != OK) { diff --git a/editor/editor_export.cpp b/editor/editor_export.cpp index e58c7c992a..90f54df485 100644 --- a/editor/editor_export.cpp +++ b/editor/editor_export.cpp @@ -913,7 +913,7 @@ Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset> &p_preset, c String tmppath = EditorSettings::get_singleton()->get_cache_dir().plus_file("packtmp"); FileAccess *ftmp = FileAccess::open(tmppath, FileAccess::WRITE); - ERR_FAIL_COND_V(!ftmp, ERR_CANT_CREATE); + ERR_FAIL_COND_V_MSG(!ftmp, ERR_CANT_CREATE, "Cannot create file '" + tmppath + "'."); PackData pd; pd.ep = &ep; @@ -1017,7 +1017,7 @@ Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset> &p_preset, c if (!ftmp) { memdelete(f); DirAccess::remove_file_or_error(tmppath); - ERR_FAIL_V_MSG(ERR_CANT_CREATE, "Can't open file to read from path: " + String(tmppath) + "."); + ERR_FAIL_V_MSG(ERR_CANT_CREATE, "Can't open file to read from path '" + String(tmppath) + "'."); } const int bufsize = 16384; diff --git a/editor/editor_feature_profile.cpp b/editor/editor_feature_profile.cpp index c6646eb28b..145931439a 100644 --- a/editor/editor_feature_profile.cpp +++ b/editor/editor_feature_profile.cpp @@ -165,7 +165,7 @@ Error EditorFeatureProfile::save_to_file(const String &p_path) { json["disabled_features"] = dis_features; FileAccessRef f = FileAccess::open(p_path, FileAccess::WRITE); - ERR_FAIL_COND_V(!f, ERR_CANT_OPEN); + ERR_FAIL_COND_V_MSG(!f, ERR_CANT_CREATE, "Cannot create file '" + p_path + "'."); String text = JSON::print(json, "\t"); f->store_string(text); @@ -326,7 +326,8 @@ void EditorFeatureProfileManager::_update_profile_list(const String &p_select_pr Vector<String> profiles; DirAccessRef d = DirAccess::open(EditorSettings::get_singleton()->get_feature_profiles_dir()); - ERR_FAIL_COND(!d); + ERR_FAIL_COND_MSG(!d, "Cannot open directory '" + EditorSettings::get_singleton()->get_feature_profiles_dir() + "'."); + d->list_dir_begin(); while (true) { String f = d->get_next(); @@ -433,7 +434,8 @@ void EditorFeatureProfileManager::_erase_selected_profile() { String selected = _get_selected_profile(); ERR_FAIL_COND(selected == String()); DirAccessRef da = DirAccess::open(EditorSettings::get_singleton()->get_feature_profiles_dir()); - ERR_FAIL_COND(!da); + ERR_FAIL_COND_MSG(!da, "Cannot open directory '" + EditorSettings::get_singleton()->get_feature_profiles_dir() + "'."); + da->remove(selected + ".profile"); if (selected == current_profile) { _profile_action(PROFILE_CLEAR); @@ -672,7 +674,7 @@ void EditorFeatureProfileManager::_update_selected_profile() { //reload edited, if different from current edited.instance(); Error err = edited->load_from_file(EditorSettings::get_singleton()->get_feature_profiles_dir().plus_file(profile + ".profile")); - ERR_FAIL_COND(err != OK); + ERR_FAIL_COND_MSG(err != OK, "Error when loading EditorSettings from file '" + EditorSettings::get_singleton()->get_feature_profiles_dir().plus_file(profile + ".profile") + "'."); } updating_features = true; diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp index 6d3377a85b..3663bdee27 100644 --- a/editor/editor_file_system.cpp +++ b/editor/editor_file_system.cpp @@ -326,7 +326,7 @@ void EditorFileSystem::_save_filesystem_cache() { FileAccess *f = FileAccess::open(fscache, FileAccess::WRITE); if (f == NULL) { - ERR_PRINTS("Error writing fscache: " + fscache); + ERR_PRINTS("Error writing fscache '" + fscache + "'."); } else { f->store_line(filesystem_settings_version_for_import); _save_filesystem_cache(filesystem, f); @@ -389,7 +389,7 @@ bool EditorFileSystem::_test_for_reimport(const String &p_path, bool p_only_impo if (err == ERR_FILE_EOF) { break; } else if (err != OK) { - ERR_PRINTS("ResourceFormatImporter::load - " + p_path + ".import:" + itos(lines) + " error: " + error_text); + ERR_PRINTS("ResourceFormatImporter::load - '" + p_path + ".import:" + itos(lines) + "' error '" + error_text + "'."); memdelete(f); return false; //parse error, try reimport manually (Avoid reimport loop on broken file) } @@ -437,7 +437,7 @@ bool EditorFileSystem::_test_for_reimport(const String &p_path, bool p_only_impo if (err == ERR_FILE_EOF) { break; } else if (err != OK) { - ERR_PRINTS("ResourceFormatImporter::load - " + p_path + ".import.md5:" + itos(lines) + " error: " + error_text); + ERR_PRINTS("ResourceFormatImporter::load - '" + p_path + ".import.md5:" + itos(lines) + "' error '" + error_text + "'."); memdelete(md5s); return false; // parse error } @@ -736,7 +736,7 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, DirAccess da->change_dir(".."); } } else { - ERR_PRINTS("Cannot go into subdir: " + E->get()); + ERR_PRINTS("Cannot go into subdir '" + E->get() + "'."); } p_progress.update(idx, total); @@ -1555,7 +1555,7 @@ Error EditorFileSystem::_reimport_group(const String &p_group_file, const Vector ERR_CONTINUE(file_importer_name == String()); if (importer_name != String() && importer_name != file_importer_name) { - print_line("one importer: " + importer_name + " the other: " + file_importer_name); + print_line("one importer '" + importer_name + "' the other '" + file_importer_name + "'."); EditorNode::get_singleton()->show_warning(vformat(TTR("There are multiple importers for different types pointing to file %s, import aborted"), p_group_file)); ERR_FAIL_V(ERR_FILE_CORRUPT); } @@ -1599,7 +1599,7 @@ Error EditorFileSystem::_reimport_group(const String &p_group_file, const Vector const String &file = E->key(); String base_path = ResourceFormatImporter::get_singleton()->get_import_base_path(file); FileAccessRef f = FileAccess::open(file + ".import", FileAccess::WRITE); - ERR_FAIL_COND_V(!f, ERR_FILE_CANT_OPEN); + ERR_FAIL_COND_V_MSG(!f, ERR_FILE_CANT_OPEN, "Cannot open import file '" + file + ".import'."); //write manually, as order matters ([remap] has to go first for performance). f->store_line("[remap]"); @@ -1660,7 +1660,7 @@ Error EditorFileSystem::_reimport_group(const String &p_group_file, const Vector // Store the md5's of the various files. These are stored separately so that the .import files can be version controlled. FileAccessRef md5s = FileAccess::open(base_path + ".md5", FileAccess::WRITE); - ERR_FAIL_COND_V(!md5s, ERR_FILE_CANT_OPEN); + ERR_FAIL_COND_V_MSG(!md5s, ERR_FILE_CANT_OPEN, "Cannot open MD5 file '" + base_path + ".md5'."); md5s->store_line("source_md5=\"" + FileAccess::get_md5(file) + "\""); if (dest_paths.size()) { @@ -1671,7 +1671,7 @@ Error EditorFileSystem::_reimport_group(const String &p_group_file, const Vector EditorFileSystemDirectory *fs = NULL; int cpos = -1; bool found = _find_file(file, &fs, cpos); - ERR_FAIL_COND_V(!found, ERR_UNCONFIGURED); + ERR_FAIL_COND_V_MSG(!found, ERR_UNCONFIGURED, "Can't find file '" + file + "'."); //update modified times, to avoid reimport fs->files[cpos]->modified_time = FileAccess::get_modified_time(file); @@ -1705,7 +1705,7 @@ void EditorFileSystem::_reimport_file(const String &p_file) { EditorFileSystemDirectory *fs = NULL; int cpos = -1; bool found = _find_file(p_file, &fs, cpos); - ERR_FAIL_COND(!found); + ERR_FAIL_COND_MSG(!found, "Can't find file '" + p_file + "'."); //try to obtain existing params @@ -1781,13 +1781,13 @@ void EditorFileSystem::_reimport_file(const String &p_file) { Error err = importer->import(p_file, base_path, params, &import_variants, &gen_files, &metadata); if (err != OK) { - ERR_PRINTS("Error importing: " + p_file); + ERR_PRINTS("Error importing '" + p_file + "'."); } //as import is complete, save the .import file FileAccess *f = FileAccess::open(p_file + ".import", FileAccess::WRITE); - ERR_FAIL_COND(!f); + ERR_FAIL_COND_MSG(!f, "Cannot open file from path '" + p_file + ".import'."); //write manually, as order matters ([remap] has to go first for performance). f->store_line("[remap]"); @@ -1872,7 +1872,8 @@ void EditorFileSystem::_reimport_file(const String &p_file) { // Store the md5's of the various files. These are stored separately so that the .import files can be version controlled. FileAccess *md5s = FileAccess::open(base_path + ".md5", FileAccess::WRITE); - ERR_FAIL_COND(!md5s); + ERR_FAIL_COND_MSG(!md5s, "Cannot open MD5 file '" + base_path + ".md5'."); + md5s->store_line("source_md5=\"" + FileAccess::get_md5(p_file) + "\""); if (dest_paths.size()) { md5s->store_line("dest_md5=\"" + FileAccess::get_multiple_md5(dest_paths) + "\"\n"); diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index a76d34e122..7ffd62e909 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -1290,7 +1290,7 @@ void EditorInspector::remove_inspector_plugin(const Ref<EditorInspectorPlugin> & } } - ERR_FAIL_COND(idx == -1); + ERR_FAIL_COND_MSG(idx == -1, "Trying to remove nonexistent inspector plugin."); for (int i = idx; i < inspector_plugin_count - 1; i++) { inspector_plugins[i] = inspector_plugins[i + 1]; } diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index a1998a1d7c..842c06dded 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -903,7 +903,7 @@ void EditorNode::_set_scene_metadata(const String &p_file, int p_idx) { } Error err = cf->save(path); - ERR_FAIL_COND(err != OK); + ERR_FAIL_COND_MSG(err != OK, "Cannot save config file to '" + path + "'."); } bool EditorNode::_find_and_save_resource(RES p_res, Map<RES, bool> &processed, int32_t flags) { @@ -2597,7 +2597,7 @@ void EditorNode::_save_screenshot(NodePath p_path) { img->flip_y(); viewport->set_clear_mode(Viewport::CLEAR_MODE_ALWAYS); Error error = img->save_png(p_path); - ERR_FAIL_COND(error != OK); + ERR_FAIL_COND_MSG(error != OK, "Cannot save screenshot to file '" + p_path + "'."); } void EditorNode::_tool_menu_option(int p_idx) { @@ -3676,7 +3676,7 @@ Ref<Texture> EditorNode::get_object_icon(const Object *p_object, const String &p } Ref<Texture> EditorNode::get_class_icon(const String &p_class, const String &p_fallback) const { - ERR_FAIL_COND_V(p_class.empty(), NULL); + ERR_FAIL_COND_V_MSG(p_class.empty(), NULL, "Class name cannot be empty."); if (gui_base->has_icon(p_class, "EditorIcons")) { return gui_base->get_icon(p_class, "EditorIcons"); diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index 30fb561fbe..7c74dc7d63 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -2038,7 +2038,7 @@ void EditorPropertyResource::_file_selected(const String &p_path) { RES res = ResourceLoader::load(p_path); - ERR_FAIL_COND(res.is_null()); + ERR_FAIL_COND_MSG(res.is_null(), "Cannot load resource from path '" + p_path + "'."); List<PropertyInfo> prop_list; get_edited_object()->get_property_list(&prop_list); diff --git a/editor/editor_resource_preview.cpp b/editor/editor_resource_preview.cpp index 5c15ebb1eb..b528cda8ff 100644 --- a/editor/editor_resource_preview.cpp +++ b/editor/editor_resource_preview.cpp @@ -203,7 +203,7 @@ void EditorResourcePreview::_generate_preview(Ref<ImageTexture> &r_texture, Ref< } Error err; FileAccess *f = FileAccess::open(cache_base + ".txt", FileAccess::WRITE, &err); - ERR_FAIL_COND(err != OK); + ERR_FAIL_COND_MSG(err != OK, "Cannot create file '" + cache_base + ".txt'."); f->store_line(itos(thumbnail_size)); f->store_line(itos(has_small_texture)); f->store_line(itos(FileAccess::get_modified_time(p_item.path))); @@ -450,7 +450,7 @@ void EditorResourcePreview::check_for_invalidation(const String &p_path) { } void EditorResourcePreview::start() { - ERR_FAIL_COND(thread); + ERR_FAIL_COND_MSG(thread, "Thread already started."); thread = Thread::create(_thread_func, this); } diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index 479fe5f0cb..9d24e443c4 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -793,13 +793,13 @@ void EditorSettings::create() { self_contained = true; Error err = extra_config->load(exe_path + "/._sc_"); if (err != OK) { - ERR_PRINTS("Can't load config from path: " + exe_path + "/._sc_"); + ERR_PRINTS("Can't load config from path '" + exe_path + "/._sc_'."); } } else if (d->file_exists(exe_path + "/_sc_")) { self_contained = true; Error err = extra_config->load(exe_path + "/_sc_"); if (err != OK) { - ERR_PRINTS("Can't load config from path: " + exe_path + "/_sc_"); + ERR_PRINTS("Can't load config from path '" + exe_path + "/_sc_'."); } } memdelete(d); @@ -1235,10 +1235,10 @@ void EditorSettings::set_project_metadata(const String &p_section, const String String path = get_project_settings_dir().plus_file("project_metadata.cfg"); Error err; err = cf->load(path); - ERR_FAIL_COND(err != OK && err != ERR_FILE_NOT_FOUND); + ERR_FAIL_COND_MSG(err != OK && err != ERR_FILE_NOT_FOUND, "Cannot load editor settings from file '" + path + "'."); cf->set_value(p_section, p_key, p_data); err = cf->save(path); - ERR_FAIL_COND(err != OK); + ERR_FAIL_COND_MSG(err != OK, "Cannot save editor settings to file '" + path + "'."); } Variant EditorSettings::get_project_metadata(const String &p_section, const String &p_key, Variant p_default) const { diff --git a/editor/export_template_manager.cpp b/editor/export_template_manager.cpp index 536cfaa1dd..324b74c6c8 100644 --- a/editor/export_template_manager.cpp +++ b/editor/export_template_manager.cpp @@ -321,7 +321,7 @@ bool ExportTemplateManager::_install_from_file(const String &p_file, bool p_use_ if (!f) { ret = unzGoToNextFile(pkg); fc++; - ERR_CONTINUE_MSG(true, "Can't open file from path: " + String(to_write) + "."); + ERR_CONTINUE_MSG(true, "Can't open file from path '" + String(to_write) + "'."); } f->store_buffer(data.ptr(), data.size()); diff --git a/editor/file_type_cache.cpp b/editor/file_type_cache.cpp index 746d38f2b5..602906cb8d 100644 --- a/editor/file_type_cache.cpp +++ b/editor/file_type_cache.cpp @@ -99,6 +99,6 @@ void FileTypeCache::save() { FileTypeCache::FileTypeCache() { - ERR_FAIL_COND(singleton); + ERR_FAIL_COND_MSG(singleton, "FileTypeCache singleton already exist."); singleton = this; } diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index a729befe8e..426ea8f196 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -1709,7 +1709,7 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected reimport.push_back(p_selected[i]); } - ERR_FAIL_COND(reimport.size() == 0); + ERR_FAIL_COND_MSG(reimport.size() == 0, "You need to select files to reimport them."); } break; case FILE_NEW_FOLDER: { @@ -2087,7 +2087,7 @@ void FileSystemDock::_get_drag_target_folder(String &target, bool &target_favori void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, Vector<String> p_paths, bool p_display_path_dependent_options) { // Add options for files and folders. - ERR_FAIL_COND(p_paths.empty()); + ERR_FAIL_COND_MSG(p_paths.empty(), "Path cannot be empty."); Vector<String> filenames; Vector<String> foldernames; diff --git a/editor/find_in_files.cpp b/editor/find_in_files.cpp index def22d07de..752e49a932 100644 --- a/editor/find_in_files.cpp +++ b/editor/find_in_files.cpp @@ -829,7 +829,7 @@ void FindInFilesPanel::apply_replaces_in_file(String fpath, const Vector<Result> // however that means either losing changes or losing replaces. FileAccess *f = FileAccess::open(fpath, FileAccess::READ); - ERR_FAIL_COND(f == NULL); + ERR_FAIL_COND_MSG(f == NULL, "Cannot open file from path '" + fpath + "'."); String buffer; int current_line = 1; @@ -876,7 +876,7 @@ void FindInFilesPanel::apply_replaces_in_file(String fpath, const Vector<Result> // Now the modified contents are in the buffer, rewrite the file with our changes Error err = f->reopen(fpath, FileAccess::WRITE); - ERR_FAIL_COND(err != OK); + ERR_FAIL_COND_MSG(err != OK, "Cannot create file in path '" + fpath + "'."); f->store_string(buffer); diff --git a/editor/import/editor_import_collada.cpp b/editor/import/editor_import_collada.cpp index 449124acec..aa4408bc13 100644 --- a/editor/import/editor_import_collada.cpp +++ b/editor/import/editor_import_collada.cpp @@ -1208,7 +1208,7 @@ Error ColladaImport::_create_resources(Collada::Node *p_node, bool p_use_compres const Collada::MeshData &meshdata = collada.state.mesh_data_map[meshid]; mesh->set_name(meshdata.name); Error err = _create_mesh_surfaces(morphs.size() == 0, mesh, ng2->material_map, meshdata, apply_xform, bone_remap, skin, morph, morphs, p_use_compression, use_mesh_builtin_materials); - ERR_FAIL_COND_V(err, err); + ERR_FAIL_COND_V_MSG(err, err, "Cannot create mesh surface."); mesh_cache[meshid] = mesh; } else { @@ -1260,7 +1260,7 @@ Error ColladaImport::_create_resources(Collada::Node *p_node, bool p_use_compres Error ColladaImport::load(const String &p_path, int p_flags, bool p_force_make_tangents, bool p_use_compression) { Error err = collada.load(p_path, p_flags); - ERR_FAIL_COND_V(err, err); + ERR_FAIL_COND_V_MSG(err, err, "Cannot load file '" + p_path + "'."); force_make_tangents = p_force_make_tangents; ERR_FAIL_COND_V(!collada.state.visual_scene_map.has(collada.state.root_visual_scene), ERR_INVALID_DATA); @@ -1778,7 +1778,7 @@ Node *EditorSceneImporterCollada::import_scene(const String &p_path, uint32_t p_ Error err = state.load(p_path, flags, p_flags & EditorSceneImporter::IMPORT_GENERATE_TANGENT_ARRAYS, p_flags & EditorSceneImporter::IMPORT_USE_COMPRESSION); - ERR_FAIL_COND_V(err != OK, NULL); + ERR_FAIL_COND_V_MSG(err != OK, NULL, "Cannot load scene from file '" + p_path + "'."); if (state.missing_textures.size()) { @@ -1831,7 +1831,7 @@ Ref<Animation> EditorSceneImporterCollada::import_animation(const String &p_path state.use_mesh_builtin_materials = false; Error err = state.load(p_path, Collada::IMPORT_FLAG_ANIMATION, p_flags & EditorSceneImporter::IMPORT_GENERATE_TANGENT_ARRAYS); - ERR_FAIL_COND_V(err != OK, RES()); + ERR_FAIL_COND_V_MSG(err != OK, RES(), "Cannot load animation from file '" + p_path + "'."); state.create_animations(p_flags & EditorSceneImporter::IMPORT_ANIMATION_FORCE_ALL_TRACKS_IN_ALL_CLIPS, p_flags & EditorSceneImporter::IMPORT_ANIMATION_KEEP_VALUE_TRACKS); if (state.scene) diff --git a/editor/import/editor_scene_importer_gltf.cpp b/editor/import/editor_scene_importer_gltf.cpp index 9ea7c86e0c..c21ac42622 100644 --- a/editor/import/editor_scene_importer_gltf.cpp +++ b/editor/import/editor_scene_importer_gltf.cpp @@ -1670,14 +1670,14 @@ Error EditorSceneImporterGLTF::_parse_animations(GLTFState &state) { track->weight_tracks.write[k] = cf; } } else { - WARN_PRINTS("Invalid path: " + path); + WARN_PRINTS("Invalid path '" + path + "'."); } } state.animations.push_back(animation); } - print_verbose("glTF: Total animations: " + itos(state.animations.size())); + print_verbose("glTF: Total animations '" + itos(state.animations.size()) + "'."); return OK; } diff --git a/editor/import/resource_importer_csv_translation.cpp b/editor/import/resource_importer_csv_translation.cpp index 301422a25a..d988e1dcc3 100644 --- a/editor/import/resource_importer_csv_translation.cpp +++ b/editor/import/resource_importer_csv_translation.cpp @@ -90,7 +90,7 @@ Error ResourceImporterCSVTranslation::import(const String &p_source_file, const FileAccessRef f = FileAccess::open(p_source_file, FileAccess::READ); - ERR_FAIL_COND_V(!f, ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V_MSG(!f, ERR_INVALID_PARAMETER, "Cannot open file from path '" + p_source_file + "'."); Vector<String> line = f->get_csv_line(delimiter); ERR_FAIL_COND_V(line.size() <= 1, ERR_PARSE_ERROR); diff --git a/editor/import/resource_importer_image.cpp b/editor/import/resource_importer_image.cpp index ed8ea5497a..3d7663ba8f 100644 --- a/editor/import/resource_importer_image.cpp +++ b/editor/import/resource_importer_image.cpp @@ -78,7 +78,7 @@ Error ResourceImporterImage::import(const String &p_source_file, const String &p FileAccess *f = FileAccess::open(p_source_file, FileAccess::READ); - ERR_FAIL_COND_V(!f, ERR_CANT_OPEN); + ERR_FAIL_COND_V_MSG(!f, ERR_CANT_OPEN, "Cannot open file from path '" + p_source_file + "'."); size_t len = f->get_len(); @@ -90,6 +90,7 @@ Error ResourceImporterImage::import(const String &p_source_file, const String &p memdelete(f); f = FileAccess::open(p_save_path + ".image", FileAccess::WRITE); + ERR_FAIL_COND_V_MSG(!f, ERR_CANT_CREATE, "Cannot create file in path '" + p_save_path + ".image'."); //save the header GDIM const uint8_t header[4] = { 'G', 'D', 'I', 'M' }; diff --git a/editor/import/resource_importer_obj.cpp b/editor/import/resource_importer_obj.cpp index 9061c92f6e..31a099ef83 100644 --- a/editor/import/resource_importer_obj.cpp +++ b/editor/import/resource_importer_obj.cpp @@ -509,7 +509,7 @@ Error ResourceImporterOBJ::import(const String &p_source_file, const String &p_s err = ResourceSaver::save(save_path, meshes.front()->get()); - ERR_FAIL_COND_V(err != OK, err); + ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot save Mesh to file '" + save_path + "'."); r_gen_files->push_back(save_path); diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp index 64994e21b0..681e82de01 100644 --- a/editor/import/resource_importer_scene.cpp +++ b/editor/import/resource_importer_scene.cpp @@ -1418,7 +1418,7 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p DirAccess *da = DirAccess::open(base_path); Error err2 = da->make_dir(subdir_name); memdelete(da); - ERR_FAIL_COND_V(err2 != OK && err2 != ERR_ALREADY_EXISTS, err2); + ERR_FAIL_COND_V_MSG(err2 != OK && err2 != ERR_ALREADY_EXISTS, err2, "Cannot make directory '" + subdir_name + "'."); base_path = base_path.plus_file(subdir_name); } } @@ -1514,7 +1514,7 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p Ref<PackedScene> packer = memnew(PackedScene); packer->pack(child); err = ResourceSaver::save(path, packer); //do not take over, let the changed files reload themselves - ERR_FAIL_COND_V(err != OK, err); + ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot save scene to file '" + path + "'."); } } @@ -1522,7 +1522,7 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p packer->pack(scene); print_verbose("Saving scene to: " + p_save_path + ".scn"); err = ResourceSaver::save(p_save_path + ".scn", packer); //do not take over, let the changed files reload themselves - ERR_FAIL_COND_V(err != OK, err); + ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot save scene to file '" + p_save_path + ".scn'."); memdelete(scene); @@ -1549,7 +1549,7 @@ Node *EditorSceneImporterESCN::import_scene(const String &p_path, uint32_t p_fla Error error; Ref<PackedScene> ps = ResourceFormatLoaderText::singleton->load(p_path, p_path, &error); - ERR_FAIL_COND_V(!ps.is_valid(), NULL); + ERR_FAIL_COND_V_MSG(!ps.is_valid(), NULL, "Cannot load scene as text resource from path '" + p_path + "'."); Node *scene = ps->instance(); ERR_FAIL_COND_V(!scene, NULL); diff --git a/editor/import/resource_importer_wav.cpp b/editor/import/resource_importer_wav.cpp index f1de71e25e..74586a4100 100644 --- a/editor/import/resource_importer_wav.cpp +++ b/editor/import/resource_importer_wav.cpp @@ -96,7 +96,7 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s Error err; FileAccess *file = FileAccess::open(p_source_file, FileAccess::READ, &err); - ERR_FAIL_COND_V(err != OK, ERR_CANT_OPEN); + ERR_FAIL_COND_V_MSG(err != OK, ERR_CANT_OPEN, "Cannot open file '" + p_source_file + "'."); /* CHECK RIFF */ char riff[5]; diff --git a/editor/plugin_config_dialog.cpp b/editor/plugin_config_dialog.cpp index 23056d25c0..971e746509 100644 --- a/editor/plugin_config_dialog.cpp +++ b/editor/plugin_config_dialog.cpp @@ -131,7 +131,7 @@ void PluginConfigDialog::config(const String &p_config_path) { if (p_config_path.length()) { Ref<ConfigFile> cf = memnew(ConfigFile); Error err = cf->load(p_config_path); - ERR_FAIL_COND(err != OK); + ERR_FAIL_COND_MSG(err != OK, "Cannot load config file from path '" + p_config_path + "'."); name_edit->set_text(cf->get_value("plugin", "name", "")); subfolder_edit->set_text(p_config_path.get_base_dir().get_basename().get_file()); diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp index 173079b6de..8625b9857c 100644 --- a/editor/plugins/animation_player_editor_plugin.cpp +++ b/editor/plugins/animation_player_editor_plugin.cpp @@ -734,8 +734,8 @@ void AnimationPlayerEditor::_dialog_action(String p_file) { ERR_FAIL_COND(!player); Ref<Resource> res = ResourceLoader::load(p_file, "Animation"); - ERR_FAIL_COND(res.is_null()); - ERR_FAIL_COND(!res->is_class("Animation")); + ERR_FAIL_COND_MSG(res.is_null(), "Cannot load Animation from file '" + p_file + "'."); + ERR_FAIL_COND_MSG(!res->is_class("Animation"), "Loaded resource from file '" + p_file + "' is not Animation."); if (p_file.find_last("/") != -1) { p_file = p_file.substr(p_file.find_last("/") + 1, p_file.length()); diff --git a/editor/plugins/cpu_particles_2d_editor_plugin.cpp b/editor/plugins/cpu_particles_2d_editor_plugin.cpp index 9d625af959..374900d4c7 100644 --- a/editor/plugins/cpu_particles_2d_editor_plugin.cpp +++ b/editor/plugins/cpu_particles_2d_editor_plugin.cpp @@ -87,7 +87,7 @@ void CPUParticles2DEditorPlugin::_generate_emission_mask() { Ref<Image> img; img.instance(); Error err = ImageLoader::load_image(source_emission_file, img); - ERR_FAIL_COND_MSG(err != OK, "Error loading image: " + source_emission_file + "."); + ERR_FAIL_COND_MSG(err != OK, "Error loading image '" + source_emission_file + "'."); if (img->is_compressed()) { img->decompress(); diff --git a/editor/plugins/curve_editor_plugin.cpp b/editor/plugins/curve_editor_plugin.cpp index c2b6031e60..98db911799 100644 --- a/editor/plugins/curve_editor_plugin.cpp +++ b/editor/plugins/curve_editor_plugin.cpp @@ -779,7 +779,7 @@ bool CurvePreviewGenerator::handles(const String &p_type) const { Ref<Texture> CurvePreviewGenerator::generate(const Ref<Resource> &p_from, const Size2 &p_size) const { Ref<Curve> curve_ref = p_from; - ERR_FAIL_COND_V(curve_ref.is_null(), Ref<Texture>()); + ERR_FAIL_COND_V_MSG(curve_ref.is_null(), Ref<Texture>(), "It's not a reference to a valid Resource object."); Curve &curve = **curve_ref; // FIXME: Should be ported to use p_size as done in b2633a97 diff --git a/editor/plugins/mesh_library_editor_plugin.cpp b/editor/plugins/mesh_library_editor_plugin.cpp index 1fc6dae978..7fbb35e565 100644 --- a/editor/plugins/mesh_library_editor_plugin.cpp +++ b/editor/plugins/mesh_library_editor_plugin.cpp @@ -201,7 +201,7 @@ void MeshLibraryEditor::_import_scene_cbk(const String &p_str) { ERR_FAIL_COND(ps.is_null()); Node *scene = ps->instance(); - ERR_FAIL_COND(!scene); + ERR_FAIL_COND_MSG(!scene, "Cannot create an instance from PackedScene '" + p_str + "'."); _import_scene(scene, mesh_library, option == MENU_OPTION_UPDATE_FROM_SCENE); diff --git a/editor/plugins/particles_2d_editor_plugin.cpp b/editor/plugins/particles_2d_editor_plugin.cpp index 8025e12885..957ce42304 100644 --- a/editor/plugins/particles_2d_editor_plugin.cpp +++ b/editor/plugins/particles_2d_editor_plugin.cpp @@ -160,7 +160,7 @@ void Particles2DEditorPlugin::_generate_emission_mask() { Ref<Image> img; img.instance(); Error err = ImageLoader::load_image(source_emission_file, img); - ERR_FAIL_COND_MSG(err != OK, "Error loading image: " + source_emission_file + "."); + ERR_FAIL_COND_MSG(err != OK, "Error loading image '" + source_emission_file + "'."); if (img->is_compressed()) { img->decompress(); diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 8b6bab374c..e43528a79e 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -1965,7 +1965,7 @@ Ref<TextFile> ScriptEditor::_load_text_file(const String &p_path, Error *r_error Ref<TextFile> text_res(text_file); Error err = text_file->load_text(path); - ERR_FAIL_COND_V(err != OK, RES()); + ERR_FAIL_COND_V_MSG(err != OK, RES(), "Cannot load text file '" + path + "'."); text_file->set_file_path(local_path); text_file->set_path(local_path, true); @@ -1990,10 +1990,7 @@ Error ScriptEditor::_save_text_file(Ref<TextFile> p_text_file, const String &p_p Error err; FileAccess *file = FileAccess::open(p_path, FileAccess::WRITE, &err); - if (err) { - - ERR_FAIL_COND_V(err, err); - } + ERR_FAIL_COND_V_MSG(err, err, "Cannot save text file '" + p_path + "'."); file->store_string(source); if (file->get_error() != OK && file->get_error() != ERR_FILE_EOF) { diff --git a/editor/plugins/theme_editor_plugin.cpp b/editor/plugins/theme_editor_plugin.cpp index 3055a9382c..d501a04016 100644 --- a/editor/plugins/theme_editor_plugin.cpp +++ b/editor/plugins/theme_editor_plugin.cpp @@ -192,7 +192,7 @@ void ThemeEditor::_save_template_cbk(String fname) { FileAccess *file = FileAccess::open(filename, FileAccess::WRITE); - ERR_FAIL_COND_MSG(!file, "Can't save theme to file: " + filename + "."); + ERR_FAIL_COND_MSG(!file, "Can't save theme to file '" + filename + "'."); file->store_line("; ******************* "); file->store_line("; Template Theme File "); diff --git a/editor/progress_dialog.cpp b/editor/progress_dialog.cpp index 8dac5fa6b5..04b863f3aa 100644 --- a/editor/progress_dialog.cpp +++ b/editor/progress_dialog.cpp @@ -38,7 +38,7 @@ void BackgroundProgress::_add_task(const String &p_task, const String &p_label, int p_steps) { _THREAD_SAFE_METHOD_ - ERR_FAIL_COND(tasks.has(p_task)); + ERR_FAIL_COND_MSG(tasks.has(p_task), "Task '" + p_task + "' already exists."); BackgroundProgress::Task t; t.hb = memnew(HBoxContainer); Label *l = memnew(Label); @@ -172,7 +172,7 @@ void ProgressDialog::add_task(const String &p_task, const String &p_label, int p return; } - ERR_FAIL_COND(tasks.has(p_task)); + ERR_FAIL_COND_MSG(tasks.has(p_task), "Task '" + p_task + "' already exists."); ProgressDialog::Task t; t.vb = memnew(VBoxContainer); VBoxContainer *vb2 = memnew(VBoxContainer); diff --git a/main/main.cpp b/main/main.cpp index 9ae885a5ce..5de5c52b14 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -1182,7 +1182,7 @@ Error Main::setup2(Thread::ID p_main_tid_override) { boot_logo.instance(); Error load_err = ImageLoader::load_image(boot_logo_path, boot_logo); if (load_err) - ERR_PRINTS("Non-existing or invalid boot splash at: " + boot_logo_path + ". Loading default splash."); + ERR_PRINTS("Non-existing or invalid boot splash at '" + boot_logo_path + "'. Loading default splash."); } Color boot_bg_color = GLOBAL_DEF("application/boot_splash/bg_color", boot_splash_bg_color); diff --git a/modules/csg/csg_shape.cpp b/modules/csg/csg_shape.cpp index 23725c4960..45f8fdd2a8 100644 --- a/modules/csg/csg_shape.cpp +++ b/modules/csg/csg_shape.cpp @@ -282,7 +282,7 @@ void CSGShape::_update_shape() { root_mesh.unref(); //byebye root mesh CSGBrush *n = _get_brush(); - ERR_FAIL_COND(!n); + ERR_FAIL_COND_MSG(!n, "Cannot get CSGBrush."); OAHashMap<Vector3, Vector3> vec_map; @@ -2407,7 +2407,7 @@ NodePath CSGPolygon::get_path_node() const { } void CSGPolygon::set_path_interval(float p_interval) { - ERR_FAIL_COND(p_interval < 0.001); + ERR_FAIL_COND_MSG(p_interval < 0.001, "Path interval cannot be smaller than 0.001."); path_interval = p_interval; _make_dirty(); update_gizmo(); diff --git a/modules/dds/texture_loader_dds.cpp b/modules/dds/texture_loader_dds.cpp index 0220dcae4a..16a0f9d6ee 100644 --- a/modules/dds/texture_loader_dds.cpp +++ b/modules/dds/texture_loader_dds.cpp @@ -108,7 +108,7 @@ RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path, if (r_error) *r_error = ERR_FILE_CORRUPT; - ERR_FAIL_COND_V_MSG(err != OK, RES(), "Unable to open DDS texture file: " + p_path + "."); + ERR_FAIL_COND_V_MSG(err != OK, RES(), "Unable to open DDS texture file '" + p_path + "'."); uint32_t magic = f->get_32(); uint32_t hsize = f->get_32(); @@ -127,7 +127,7 @@ RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path, if (magic != DDS_MAGIC || hsize != 124 || !(flags & DDSD_PIXELFORMAT) || !(flags & DDSD_CAPS)) { - ERR_FAIL_V_MSG(RES(), "Invalid or unsupported DDS texture file: " + p_path + "."); + ERR_FAIL_V_MSG(RES(), "Invalid or unsupported DDS texture file '" + p_path + "'."); } /* uint32_t format_size = */ f->get_32(); @@ -216,7 +216,7 @@ RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path, } else { printf("unrecognized fourcc %x format_flags: %x - rgbbits %i - red_mask %x green mask %x blue mask %x alpha mask %x\n", format_fourcc, format_flags, format_rgb_bits, format_red_mask, format_green_mask, format_blue_mask, format_alpha_mask); - ERR_FAIL_V_MSG(RES(), "Unrecognized or unsupported color layout in DDS: " + p_path + "."); + ERR_FAIL_V_MSG(RES(), "Unrecognized or unsupported color layout in DDS '" + p_path + "'."); } if (!(flags & DDSD_MIPMAPCOUNT)) diff --git a/modules/enet/networked_multiplayer_enet.cpp b/modules/enet/networked_multiplayer_enet.cpp index 44f69ca261..a787cd3b80 100644 --- a/modules/enet/networked_multiplayer_enet.cpp +++ b/modules/enet/networked_multiplayer_enet.cpp @@ -543,7 +543,7 @@ Error NetworkedMultiplayerENet::put_packet(const uint8_t *p_buffer, int p_buffer if (target_peer != 0) { E = peer_map.find(ABS(target_peer)); - ERR_FAIL_COND_V_MSG(!E, ERR_INVALID_PARAMETER, "Invalid target peer: " + itos(target_peer) + "."); + ERR_FAIL_COND_V_MSG(!E, ERR_INVALID_PARAMETER, "Invalid target peer '" + itos(target_peer) + "'."); } ENetPacket *packet = enet_packet_create(NULL, p_buffer_size + 8, packet_flags); diff --git a/modules/etc/texture_loader_pkm.cpp b/modules/etc/texture_loader_pkm.cpp index dd61d816d4..4d8af6883f 100644 --- a/modules/etc/texture_loader_pkm.cpp +++ b/modules/etc/texture_loader_pkm.cpp @@ -56,14 +56,14 @@ RES ResourceFormatPKM::load(const String &p_path, const String &p_original_path, if (r_error) *r_error = ERR_FILE_CORRUPT; - ERR_FAIL_COND_V_MSG(err != OK, RES(), "Unable to open PKM texture file: " + p_path + "."); + ERR_FAIL_COND_V_MSG(err != OK, RES(), "Unable to open PKM texture file '" + p_path + "'."); // big endian f->set_endian_swap(true); ETC1Header h; f->get_buffer((uint8_t *)&h.tag, sizeof(h.tag)); - ERR_FAIL_COND_V_MSG(strncmp(h.tag, "PKM 10", sizeof(h.tag)), RES(), "Invalid or unsupported PKM texture file: " + p_path + "."); + ERR_FAIL_COND_V_MSG(strncmp(h.tag, "PKM 10", sizeof(h.tag)), RES(), "Invalid or unsupported PKM texture file '" + p_path + "'."); h.format = f->get_16(); h.texWidth = f->get_16(); diff --git a/modules/gdnative/pluginscript/pluginscript_script.cpp b/modules/gdnative/pluginscript/pluginscript_script.cpp index 94d38e1be1..f7c961d38b 100644 --- a/modules/gdnative/pluginscript/pluginscript_script.cpp +++ b/modules/gdnative/pluginscript/pluginscript_script.cpp @@ -401,9 +401,7 @@ Error PluginScript::load_source_code(const String &p_path) { PoolVector<uint8_t> sourcef; Error err; FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err); - if (err) { - ERR_FAIL_COND_V(err, err); - } + ERR_FAIL_COND_V_MSG(err, err, "Cannot open file '" + p_path + "'."); int len = f->get_len(); sourcef.resize(len + 1); diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index 5dab063061..ea2296692c 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -2177,11 +2177,11 @@ RES ResourceFormatLoaderGDScript::load(const String &p_path, const String &p_ori script->set_script_path(p_original_path); // script needs this. script->set_path(p_original_path); Error err = script->load_byte_code(p_path); - ERR_FAIL_COND_V(err != OK, RES()); + ERR_FAIL_COND_V_MSG(err != OK, RES(), "Cannot load byte code from file '" + p_path + "'."); } else { Error err = script->load_source_code(p_path); - ERR_FAIL_COND_V(err != OK, RES()); + ERR_FAIL_COND_V_MSG(err != OK, RES(), "Cannot load source code from file '" + p_path + "'."); script->set_script_path(p_original_path); // script needs this. script->set_path(p_original_path); @@ -2217,7 +2217,7 @@ String ResourceFormatLoaderGDScript::get_resource_type(const String &p_path) con void ResourceFormatLoaderGDScript::get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types) { FileAccessRef file = FileAccess::open(p_path, FileAccess::READ); - ERR_FAIL_COND(!file); + ERR_FAIL_COND_MSG(!file, "Cannot open file '" + p_path + "'."); String source = file->get_as_utf8_string(); if (source.empty()) { @@ -2244,10 +2244,7 @@ Error ResourceFormatSaverGDScript::save(const String &p_path, const RES &p_resou Error err; FileAccess *file = FileAccess::open(p_path, FileAccess::WRITE, &err); - if (err) { - - ERR_FAIL_COND_V(err, err); - } + ERR_FAIL_COND_V_MSG(err, err, "Cannot save GDScript file '" + p_path + "'."); file->store_string(source); if (file->get_error() != OK && file->get_error() != ERR_FILE_EOF) { diff --git a/modules/gdscript/gdscript_tokenizer.cpp b/modules/gdscript/gdscript_tokenizer.cpp index 64b354bdb8..8b20b0ff48 100644 --- a/modules/gdscript/gdscript_tokenizer.cpp +++ b/modules/gdscript/gdscript_tokenizer.cpp @@ -1425,7 +1425,7 @@ Vector<uint8_t> GDScriptTokenizerBuffer::parse_code_string(const String &p_code) int len; // Objects cannot be constant, never encode objects Error err = encode_variant(E->get(), NULL, len, false); - ERR_FAIL_COND_V(err != OK, Vector<uint8_t>()); + ERR_FAIL_COND_V_MSG(err != OK, Vector<uint8_t>(), "Error when trying to encode Variant."); int pos = buf.size(); buf.resize(pos + len); encode_variant(E->get(), &buf.write[pos], len, false); diff --git a/modules/mbedtls/crypto_mbedtls.cpp b/modules/mbedtls/crypto_mbedtls.cpp index 1e02084ae2..ca656b4b9b 100644 --- a/modules/mbedtls/crypto_mbedtls.cpp +++ b/modules/mbedtls/crypto_mbedtls.cpp @@ -55,7 +55,7 @@ Error CryptoKeyMbedTLS::load(String p_path) { PoolByteArray out; FileAccess *f = FileAccess::open(p_path, FileAccess::READ); - ERR_FAIL_COND_V(!f, ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V_MSG(!f, ERR_INVALID_PARAMETER, "Cannot open CryptoKeyMbedTLS file '" + p_path + "'."); int flen = f->get_len(); out.resize(flen + 1); @@ -69,14 +69,14 @@ Error CryptoKeyMbedTLS::load(String p_path) { int ret = mbedtls_pk_parse_key(&pkey, out.read().ptr(), out.size(), NULL, 0); // We MUST zeroize the memory for safety! mbedtls_platform_zeroize(out.write().ptr(), out.size()); - ERR_FAIL_COND_V_MSG(ret, FAILED, "Error parsing private key: " + itos(ret)); + ERR_FAIL_COND_V_MSG(ret, FAILED, "Error parsing private key '" + itos(ret) + "'."); return OK; } Error CryptoKeyMbedTLS::save(String p_path) { FileAccess *f = FileAccess::open(p_path, FileAccess::WRITE); - ERR_FAIL_COND_V(!f, ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V_MSG(!f, ERR_INVALID_PARAMETER, "Cannot save CryptoKeyMbedTLS file '" + p_path + "'."); unsigned char w[16000]; memset(w, 0, sizeof(w)); @@ -85,7 +85,7 @@ Error CryptoKeyMbedTLS::save(String p_path) { if (ret != 0) { memdelete(f); memset(w, 0, sizeof(w)); // Zeroize anything we might have written. - ERR_FAIL_V_MSG(FAILED, "Error writing key: " + itos(ret)); + ERR_FAIL_V_MSG(FAILED, "Error writing key '" + itos(ret) + "'."); } size_t len = strlen((char *)w); @@ -104,7 +104,7 @@ Error X509CertificateMbedTLS::load(String p_path) { PoolByteArray out; FileAccess *f = FileAccess::open(p_path, FileAccess::READ); - ERR_FAIL_COND_V(!f, ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V_MSG(!f, ERR_INVALID_PARAMETER, "Cannot open X509CertificateMbedTLS file '" + p_path + "'."); int flen = f->get_len(); out.resize(flen + 1); @@ -131,7 +131,7 @@ Error X509CertificateMbedTLS::load_from_memory(const uint8_t *p_buffer, int p_le Error X509CertificateMbedTLS::save(String p_path) { FileAccess *f = FileAccess::open(p_path, FileAccess::WRITE); - ERR_FAIL_COND_V(!f, ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V_MSG(!f, ERR_INVALID_PARAMETER, "Cannot save X509CertificateMbedTLS file '" + p_path + "'."); mbedtls_x509_crt *crt = &cert; while (crt) { @@ -140,7 +140,7 @@ Error X509CertificateMbedTLS::save(String p_path) { int ret = mbedtls_pem_write_buffer(PEM_BEGIN_CRT, PEM_END_CRT, cert.raw.p, cert.raw.len, w, sizeof(w), &wrote); if (ret != 0 || wrote == 0) { memdelete(f); - ERR_FAIL_V_MSG(FAILED, "Error writing certificate: " + itos(ret)); + ERR_FAIL_V_MSG(FAILED, "Error writing certificate '" + itos(ret) + "'."); } f->store_buffer(w, wrote - 1); // don't write the string terminator diff --git a/modules/mono/class_db_api_json.cpp b/modules/mono/class_db_api_json.cpp index 7580911a0a..bbc779601e 100644 --- a/modules/mono/class_db_api_json.cpp +++ b/modules/mono/class_db_api_json.cpp @@ -236,7 +236,7 @@ void class_db_api_to_json(const String &p_output_file, ClassDB::APIType p_api) { } FileAccessRef f = FileAccess::open(p_output_file, FileAccess::WRITE); - ERR_FAIL_COND(!f); + ERR_FAIL_COND_MSG(!f, "Cannot open file '" + p_output_file + "'."); f->store_string(JSON::print(classes_dict, /*indent: */ "\t")); f->close(); diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp index e14e919f92..83be10dee3 100644 --- a/modules/mono/csharp_script.cpp +++ b/modules/mono/csharp_script.cpp @@ -1195,7 +1195,7 @@ void CSharpLanguage::release_script_gchandle(MonoObject *p_expected_obj, Ref<Mon CSharpLanguage::CSharpLanguage() { - ERR_FAIL_COND(singleton); + ERR_FAIL_COND_MSG(singleton, "C# singleton already exist."); singleton = this; finalizing = false; @@ -3242,7 +3242,7 @@ RES ResourceFormatLoaderCSharpScript::load(const String &p_path, const String &p #if defined(DEBUG_ENABLED) || defined(TOOLS_ENABLED) Error err = script->load_source_code(p_path); - ERR_FAIL_COND_V(err != OK, RES()); + ERR_FAIL_COND_V_MSG(err != OK, RES(), "Cannot load C# script file '" + p_path + "'."); #endif script->set_path(p_original_path); @@ -3325,7 +3325,7 @@ Error ResourceFormatSaverCSharpScript::save(const String &p_path, const RES &p_r Error err; FileAccess *file = FileAccess::open(p_path, FileAccess::WRITE, &err); - ERR_FAIL_COND_V(err, err); + ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot save C# script file '" + p_path + "'."); file->store_string(source); diff --git a/modules/mono/editor/bindings_generator.cpp b/modules/mono/editor/bindings_generator.cpp index 1888bb3cb9..e98db02d66 100644 --- a/modules/mono/editor/bindings_generator.cpp +++ b/modules/mono/editor/bindings_generator.cpp @@ -868,7 +868,7 @@ Error BindingsGenerator::generate_cs_core_project(const String &p_proj_dir, Vect if (!DirAccess::exists(p_proj_dir)) { Error err = da->make_dir_recursive(p_proj_dir); - ERR_FAIL_COND_V(err != OK, ERR_CANT_CREATE); + ERR_FAIL_COND_V_MSG(err != OK, ERR_CANT_CREATE, "Cannot create directory '" + p_proj_dir + "'."); } da->change_dir(p_proj_dir); diff --git a/modules/mono/mono_gd/gd_mono_log.cpp b/modules/mono/mono_gd/gd_mono_log.cpp index 5a0d728953..52f9eac638 100644 --- a/modules/mono/mono_gd/gd_mono_log.cpp +++ b/modules/mono/mono_gd/gd_mono_log.cpp @@ -104,7 +104,7 @@ void GDMonoLog::_delete_old_log_files(const String &p_logs_dir) { ERR_FAIL_COND(!da); Error err = da->change_dir(p_logs_dir); - ERR_FAIL_COND(err != OK); + ERR_FAIL_COND_MSG(err != OK, "Cannot change directory to '" + p_logs_dir + "'."); ERR_FAIL_COND(da->list_dir_begin() != OK); diff --git a/modules/mono/utils/string_utils.cpp b/modules/mono/utils/string_utils.cpp index ae5a2cde81..3557e8de3a 100644 --- a/modules/mono/utils/string_utils.cpp +++ b/modules/mono/utils/string_utils.cpp @@ -165,7 +165,7 @@ Error read_all_file_utf8(const String &p_path, String &r_content) { PoolVector<uint8_t> sourcef; Error err; FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err); - ERR_FAIL_COND_V(err != OK, err); + ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot open file '" + p_path + "'."); int len = f->get_len(); sourcef.resize(len + 1); diff --git a/modules/opus/audio_stream_opus.cpp b/modules/opus/audio_stream_opus.cpp index d3e8d3c9bb..43b0aecbf1 100644 --- a/modules/opus/audio_stream_opus.cpp +++ b/modules/opus/audio_stream_opus.cpp @@ -119,9 +119,7 @@ Error AudioStreamPlaybackOpus::_load_stream() { Error err; f = FileAccess::open(file, FileAccess::READ, &err); - if (err) { - ERR_FAIL_COND_V(err, err); - } + ERR_FAIL_COND_V_MSG(err, err, "Cannot open file '" + file + "'."); int _err = 0; @@ -185,9 +183,7 @@ Error AudioStreamPlaybackOpus::set_file(const String &p_file) { Error err; f = FileAccess::open(file, FileAccess::READ, &err); - if (err) { - ERR_FAIL_COND_V(err, err); - } + ERR_FAIL_COND_V_MSG(err, err, "Cannot open file '" + file + "'."); int _err; diff --git a/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp b/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp index e10f29e310..977ff064bc 100644 --- a/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp +++ b/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp @@ -83,7 +83,7 @@ Error ResourceImporterOGGVorbis::import(const String &p_source_file, const Strin FileAccess *f = FileAccess::open(p_source_file, FileAccess::READ); - ERR_FAIL_COND_V(!f, ERR_CANT_OPEN); + ERR_FAIL_COND_V_MSG(!f, ERR_CANT_OPEN, "Cannot open file '" + p_source_file + "'."); size_t len = f->get_len(); diff --git a/modules/theora/video_stream_theora.cpp b/modules/theora/video_stream_theora.cpp index 6a1b463305..28a8b77283 100644 --- a/modules/theora/video_stream_theora.cpp +++ b/modules/theora/video_stream_theora.cpp @@ -175,7 +175,7 @@ void VideoStreamPlaybackTheora::set_file(const String &p_file) { memdelete(file); } file = FileAccess::open(p_file, FileAccess::READ); - ERR_FAIL_COND(!file); + ERR_FAIL_COND_MSG(!file, "Cannot open file '" + p_file + "'."); #ifdef THEORA_USE_THREAD_STREAMING thread_exit = false; diff --git a/modules/vorbis/audio_stream_ogg_vorbis.cpp b/modules/vorbis/audio_stream_ogg_vorbis.cpp index 2f56e778b9..c330af60a4 100644 --- a/modules/vorbis/audio_stream_ogg_vorbis.cpp +++ b/modules/vorbis/audio_stream_ogg_vorbis.cpp @@ -242,10 +242,7 @@ Error AudioStreamPlaybackOGGVorbis::set_file(const String &p_file) { stream_valid = false; Error err; f = FileAccess::open(file, FileAccess::READ, &err); - - if (err) { - ERR_FAIL_COND_V(err, err); - } + ERR_FAIL_COND_V_MSG(err, err, "Cannot open file '" + p_file + "'."); int errv = ov_open_callbacks(f, &vf, NULL, 0, _ov_callbacks); switch (errv) { @@ -294,9 +291,7 @@ Error AudioStreamPlaybackOGGVorbis::_load_stream() { Error err; f = FileAccess::open(file, FileAccess::READ, &err); - if (err) { - ERR_FAIL_COND_V(err, err); - } + ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot open file '" + file + "'."); int errv = ov_open_callbacks(f, &vf, NULL, 0, _ov_callbacks); switch (errv) { diff --git a/platform/android/export/export.cpp b/platform/android/export/export.cpp index 441fa38bff..e019e5bd2f 100644 --- a/platform/android/export/export.cpp +++ b/platform/android/export/export.cpp @@ -598,7 +598,7 @@ class EditorExportPlatformAndroid : public EditorExportPlatform { String dst_path = String("lib").plus_file(abi).plus_file(p_so.path.get_file()); Vector<uint8_t> array = FileAccess::get_file_as_array(p_so.path); Error store_err = store_in_apk(ed, dst_path, array); - ERR_FAIL_COND_V(store_err, store_err); + ERR_FAIL_COND_V_MSG(store_err, store_err, "Cannot store in apk file '" + dst_path + "'."); } } if (!exported) { @@ -1666,7 +1666,7 @@ public: DirAccessRef da = DirAccess::open("res://android"); - ERR_FAIL_COND(!da); + ERR_FAIL_COND_MSG(!da, "Cannot open directory 'res://android'."); Map<String, List<String> > directory_paths; Map<String, List<String> > manifest_sections; Map<String, List<String> > gradle_sections; @@ -1942,7 +1942,7 @@ public: //build project if custom build is enabled String sdk_path = EDITOR_GET("export/android/custom_build_sdk_path"); - ERR_FAIL_COND_V(sdk_path == "", ERR_UNCONFIGURED); + ERR_FAIL_COND_V_MSG(sdk_path == "", ERR_UNCONFIGURED, "Android SDK path must be configured in Editor Settings at 'export/android/custom_build_sdk_path'."); _update_custom_build_project(); diff --git a/platform/android/file_access_jandroid.cpp b/platform/android/file_access_jandroid.cpp index 5b8cf01138..d4c2a23aa0 100644 --- a/platform/android/file_access_jandroid.cpp +++ b/platform/android/file_access_jandroid.cpp @@ -94,13 +94,13 @@ void FileAccessJAndroid::seek(size_t p_position) { JNIEnv *env = ThreadAndroid::get_env(); - ERR_FAIL_COND(!is_open()); + ERR_FAIL_COND_MSG(!is_open(), "File must be opened before use."); env->CallVoidMethod(io, _file_seek, id, p_position); } void FileAccessJAndroid::seek_end(int64_t p_position) { - ERR_FAIL_COND(!is_open()); + ERR_FAIL_COND_MSG(!is_open(), "File must be opened before use."); seek(get_len()); } @@ -108,34 +108,34 @@ void FileAccessJAndroid::seek_end(int64_t p_position) { size_t FileAccessJAndroid::get_position() const { JNIEnv *env = ThreadAndroid::get_env(); - ERR_FAIL_COND_V(!is_open(), 0); + ERR_FAIL_COND_V_MSG(!is_open(), 0, "File must be opened before use."); return env->CallIntMethod(io, _file_tell, id); } size_t FileAccessJAndroid::get_len() const { JNIEnv *env = ThreadAndroid::get_env(); - ERR_FAIL_COND_V(!is_open(), 0); + ERR_FAIL_COND_V_MSG(!is_open(), 0, "File must be opened before use."); return env->CallIntMethod(io, _file_get_size, id); } bool FileAccessJAndroid::eof_reached() const { JNIEnv *env = ThreadAndroid::get_env(); - ERR_FAIL_COND_V(!is_open(), 0); + ERR_FAIL_COND_V_MSG(!is_open(), 0, "File must be opened before use."); return env->CallIntMethod(io, _file_eof, id); } uint8_t FileAccessJAndroid::get_8() const { - ERR_FAIL_COND_V(!is_open(), 0); + ERR_FAIL_COND_V_MSG(!is_open(), 0, "File must be opened before use."); uint8_t byte; get_buffer(&byte, 1); return byte; } int FileAccessJAndroid::get_buffer(uint8_t *p_dst, int p_length) const { - ERR_FAIL_COND_V(!is_open(), 0); + ERR_FAIL_COND_V_MSG(!is_open(), 0, "File must be opened before use."); if (p_length == 0) return 0; JNIEnv *env = ThreadAndroid::get_env(); diff --git a/platform/iphone/export/export.cpp b/platform/iphone/export/export.cpp index 1cbf4d6a70..1b2b343530 100644 --- a/platform/iphone/export/export.cpp +++ b/platform/iphone/export/export.cpp @@ -487,7 +487,7 @@ Error EditorExportPlatformIOS::_export_icons(const Ref<EditorExportPreset> &p_pr String sizes; DirAccess *da = DirAccess::open(p_iconset_dir); - ERR_FAIL_COND_V(!da, ERR_CANT_OPEN); + ERR_FAIL_COND_V_MSG(!da, ERR_CANT_OPEN, "Cannot open directory '" + p_iconset_dir + "'."); for (unsigned int i = 0; i < (sizeof(icon_infos) / sizeof(icon_infos[0])); ++i) { IconInfo info = icon_infos[i]; @@ -537,7 +537,7 @@ Error EditorExportPlatformIOS::_export_icons(const Ref<EditorExportPreset> &p_pr Error EditorExportPlatformIOS::_export_loading_screens(const Ref<EditorExportPreset> &p_preset, const String &p_dest_dir) { DirAccess *da = DirAccess::open(p_dest_dir); - ERR_FAIL_COND_V(!da, ERR_CANT_OPEN); + ERR_FAIL_COND_V_MSG(!da, ERR_CANT_OPEN, "Cannot open directory '" + p_dest_dir + "'."); for (unsigned int i = 0; i < sizeof(loading_screen_infos) / sizeof(loading_screen_infos[0]); ++i) { LoadingScreenInfo info = loading_screen_infos[i]; @@ -546,7 +546,7 @@ Error EditorExportPlatformIOS::_export_loading_screens(const Ref<EditorExportPre Error err = da->copy(loading_screen_file, p_dest_dir + info.export_name); if (err) { memdelete(da); - String err_str = String("Failed to export loading screen (") + info.preset_key + ") from path: " + loading_screen_file; + String err_str = String("Failed to export loading screen (") + info.preset_key + ") from path '" + loading_screen_file + "'."; ERR_PRINT(err_str.utf8().get_data()); return err; } @@ -757,7 +757,7 @@ void EditorExportPlatformIOS::_add_assets_to_project(const Ref<EditorExportPrese Error EditorExportPlatformIOS::_export_additional_assets(const String &p_out_dir, const Vector<String> &p_assets, bool p_is_framework, Vector<IOSExportAsset> &r_exported_assets) { DirAccess *filesystem_da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); - ERR_FAIL_COND_V(!filesystem_da, ERR_CANT_CREATE); + ERR_FAIL_COND_V_MSG(!filesystem_da, ERR_CANT_CREATE, "Cannot create DirAccess for path '" + p_out_dir + "'."); for (int f_idx = 0; f_idx < p_assets.size(); ++f_idx) { String asset = p_assets[f_idx]; if (!asset.begins_with("res://")) { diff --git a/platform/javascript/api/api.cpp b/platform/javascript/api/api.cpp index d4dc43d57c..0832ae0360 100644 --- a/platform/javascript/api/api.cpp +++ b/platform/javascript/api/api.cpp @@ -55,7 +55,7 @@ JavaScript *JavaScript::get_singleton() { JavaScript::JavaScript() { - ERR_FAIL_COND(singleton != NULL); + ERR_FAIL_COND_MSG(singleton != NULL, "JavaScript singleton already exist."); singleton = this; } diff --git a/platform/uwp/export/export.cpp b/platform/uwp/export/export.cpp index ea110b11ca..d83061df89 100644 --- a/platform/uwp/export/export.cpp +++ b/platform/uwp/export/export.cpp @@ -1249,7 +1249,7 @@ public: Error err = OK; FileAccess *fa_pack = FileAccess::open(p_path, FileAccess::WRITE, &err); - ERR_FAIL_COND_V(err != OK, ERR_CANT_CREATE); + ERR_FAIL_COND_V_MSG(err != OK, ERR_CANT_CREATE, "Cannot create file '" + p_path + "'."); AppxPackager packager; packager.init(fa_pack); diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index be325381bb..facf5b8d91 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -2663,7 +2663,7 @@ String OS_Windows::get_executable_path() const { void OS_Windows::set_native_icon(const String &p_filename) { FileAccess *f = FileAccess::open(p_filename, FileAccess::READ); - ERR_FAIL_COND(!f); + ERR_FAIL_COND_MSG(!f, "Cannot open file with icon '" + p_filename + "'."); ICONDIR *icon_dir = (ICONDIR *)memalloc(sizeof(ICONDIR)); int pos = 0; diff --git a/scene/2d/animated_sprite.cpp b/scene/2d/animated_sprite.cpp index 0b20b781f0..20ec06f033 100644 --- a/scene/2d/animated_sprite.cpp +++ b/scene/2d/animated_sprite.cpp @@ -102,7 +102,7 @@ Rect2 AnimatedSprite::_get_rect() const { void SpriteFrames::add_frame(const StringName &p_anim, const Ref<Texture> &p_frame, int p_at_pos) { Map<StringName, Anim>::Element *E = animations.find(p_anim); - ERR_FAIL_COND(!E); + ERR_FAIL_COND_MSG(!E, "Animation '" + String(p_anim) + "' doesn't exist."); if (p_at_pos >= 0 && p_at_pos < E->get().frames.size()) E->get().frames.insert(p_at_pos, p_frame); @@ -114,7 +114,7 @@ void SpriteFrames::add_frame(const StringName &p_anim, const Ref<Texture> &p_fra int SpriteFrames::get_frame_count(const StringName &p_anim) const { const Map<StringName, Anim>::Element *E = animations.find(p_anim); - ERR_FAIL_COND_V(!E, 0); + ERR_FAIL_COND_V_MSG(!E, 0, "Animation '" + String(p_anim) + "' doesn't exist."); return E->get().frames.size(); } @@ -122,7 +122,7 @@ int SpriteFrames::get_frame_count(const StringName &p_anim) const { void SpriteFrames::remove_frame(const StringName &p_anim, int p_idx) { Map<StringName, Anim>::Element *E = animations.find(p_anim); - ERR_FAIL_COND(!E); + ERR_FAIL_COND_MSG(!E, "Animation '" + String(p_anim) + "' doesn't exist."); E->get().frames.remove(p_idx); emit_changed(); @@ -130,7 +130,7 @@ void SpriteFrames::remove_frame(const StringName &p_anim, int p_idx) { void SpriteFrames::clear(const StringName &p_anim) { Map<StringName, Anim>::Element *E = animations.find(p_anim); - ERR_FAIL_COND(!E); + ERR_FAIL_COND_MSG(!E, "Animation '" + String(p_anim) + "' doesn't exist."); E->get().frames.clear(); emit_changed(); @@ -144,7 +144,7 @@ void SpriteFrames::clear_all() { void SpriteFrames::add_animation(const StringName &p_anim) { - ERR_FAIL_COND(animations.has(p_anim)); + ERR_FAIL_COND_MSG(animations.has(p_anim), "SpriteFrames already has animation '" + p_anim + "'."); animations[p_anim] = Anim(); animations[p_anim].normal_name = String(p_anim) + NORMAL_SUFFIX; @@ -161,8 +161,8 @@ void SpriteFrames::remove_animation(const StringName &p_anim) { void SpriteFrames::rename_animation(const StringName &p_prev, const StringName &p_next) { - ERR_FAIL_COND(!animations.has(p_prev)); - ERR_FAIL_COND(animations.has(p_next)); + ERR_FAIL_COND_MSG(!animations.has(p_prev), "SpriteFrames doesn't have animation '" + String(p_prev) + "'."); + ERR_FAIL_COND_MSG(animations.has(p_next), "Animation '" + String(p_next) + "' already exists."); Anim anim = animations[p_prev]; animations.erase(p_prev); @@ -202,26 +202,26 @@ Vector<String> SpriteFrames::get_animation_names() const { void SpriteFrames::set_animation_speed(const StringName &p_anim, float p_fps) { - ERR_FAIL_COND(p_fps < 0); + ERR_FAIL_COND_MSG(p_fps < 0, "Animation speed cannot be negative (" + itos(p_fps) + ")."); Map<StringName, Anim>::Element *E = animations.find(p_anim); - ERR_FAIL_COND(!E); + ERR_FAIL_COND_MSG(!E, "Animation '" + String(p_anim) + "' doesn't exist."); E->get().speed = p_fps; } float SpriteFrames::get_animation_speed(const StringName &p_anim) const { const Map<StringName, Anim>::Element *E = animations.find(p_anim); - ERR_FAIL_COND_V(!E, 0); + ERR_FAIL_COND_V_MSG(!E, 0, "Animation '" + String(p_anim) + "' doesn't exist."); return E->get().speed; } void SpriteFrames::set_animation_loop(const StringName &p_anim, bool p_loop) { Map<StringName, Anim>::Element *E = animations.find(p_anim); - ERR_FAIL_COND(!E); + ERR_FAIL_COND_MSG(!E, "Animation '" + String(p_anim) + "' doesn't exist."); E->get().loop = p_loop; } bool SpriteFrames::get_animation_loop(const StringName &p_anim) const { const Map<StringName, Anim>::Element *E = animations.find(p_anim); - ERR_FAIL_COND_V(!E, false); + ERR_FAIL_COND_V_MSG(!E, false, "Animation '" + String(p_anim) + "' doesn't exist."); return E->get().loop; } diff --git a/scene/2d/animated_sprite.h b/scene/2d/animated_sprite.h index 2cc372bd93..3192d44678 100644 --- a/scene/2d/animated_sprite.h +++ b/scene/2d/animated_sprite.h @@ -85,7 +85,7 @@ public: _FORCE_INLINE_ Ref<Texture> get_frame(const StringName &p_anim, int p_idx) const { const Map<StringName, Anim>::Element *E = animations.find(p_anim); - ERR_FAIL_COND_V(!E, Ref<Texture>()); + ERR_FAIL_COND_V_MSG(!E, Ref<Texture>(), "Animation '" + String(p_anim) + "' doesn't exist."); ERR_FAIL_COND_V(p_idx < 0, Ref<Texture>()); if (p_idx >= E->get().frames.size()) return Ref<Texture>(); @@ -96,7 +96,7 @@ public: _FORCE_INLINE_ Ref<Texture> get_normal_frame(const StringName &p_anim, int p_idx) const { const Map<StringName, Anim>::Element *E = animations.find(p_anim); - ERR_FAIL_COND_V(!E, Ref<Texture>()); + ERR_FAIL_COND_V_MSG(!E, Ref<Texture>(), "Animation '" + String(p_anim) + "' doesn't exist."); ERR_FAIL_COND_V(p_idx < 0, Ref<Texture>()); const Map<StringName, Anim>::Element *EN = animations.find(E->get().normal_name); @@ -109,7 +109,7 @@ public: void set_frame(const StringName &p_anim, int p_idx, const Ref<Texture> &p_frame) { Map<StringName, Anim>::Element *E = animations.find(p_anim); - ERR_FAIL_COND(!E); + ERR_FAIL_COND_MSG(!E, "Animation '" + String(p_anim) + "' doesn't exist."); ERR_FAIL_COND(p_idx < 0); if (p_idx >= E->get().frames.size()) return; diff --git a/scene/2d/area_2d.cpp b/scene/2d/area_2d.cpp index a636eea285..66a1318cb7 100644 --- a/scene/2d/area_2d.cpp +++ b/scene/2d/area_2d.cpp @@ -438,7 +438,7 @@ bool Area2D::is_monitorable() const { Array Area2D::get_overlapping_bodies() const { - ERR_FAIL_COND_V(!monitoring, Array()); + ERR_FAIL_COND_V_MSG(!monitoring, Array(), "Can't find overlapping bodies when monitoring is off."); Array ret; ret.resize(body_map.size()); int idx = 0; @@ -456,7 +456,7 @@ Array Area2D::get_overlapping_bodies() const { Array Area2D::get_overlapping_areas() const { - ERR_FAIL_COND_V(!monitoring, Array()); + ERR_FAIL_COND_V_MSG(!monitoring, Array(), "Can't find overlapping bodies when monitoring is off."); Array ret; ret.resize(area_map.size()); int idx = 0; diff --git a/scene/2d/cpu_particles_2d.cpp b/scene/2d/cpu_particles_2d.cpp index f9f273d494..e1009d9a6c 100644 --- a/scene/2d/cpu_particles_2d.cpp +++ b/scene/2d/cpu_particles_2d.cpp @@ -44,7 +44,7 @@ void CPUParticles2D::set_emitting(bool p_emitting) { void CPUParticles2D::set_amount(int p_amount) { - ERR_FAIL_COND(p_amount < 1); + ERR_FAIL_COND_MSG(p_amount < 1, "Amount of particles must be greater than 0."); particles.resize(p_amount); { @@ -62,7 +62,7 @@ void CPUParticles2D::set_amount(int p_amount) { } void CPUParticles2D::set_lifetime(float p_lifetime) { - ERR_FAIL_COND(p_lifetime <= 0); + ERR_FAIL_COND_MSG(p_lifetime <= 0, "Particles lifetime must be greater than 0."); lifetime = p_lifetime; } @@ -1122,8 +1122,9 @@ void CPUParticles2D::_notification(int p_what) { } void CPUParticles2D::convert_from_particles(Node *p_particles) { + Particles2D *particles = Object::cast_to<Particles2D>(p_particles); - ERR_FAIL_COND(!particles); + ERR_FAIL_COND_MSG(!particles, "Only Particles2D nodes can be converted to CPUParticles2D."); set_emitting(particles->is_emitting()); set_amount(particles->get_amount()); diff --git a/scene/2d/particles_2d.cpp b/scene/2d/particles_2d.cpp index 93c12f0103..0bf8237d37 100644 --- a/scene/2d/particles_2d.cpp +++ b/scene/2d/particles_2d.cpp @@ -51,13 +51,13 @@ void Particles2D::set_emitting(bool p_emitting) { void Particles2D::set_amount(int p_amount) { - ERR_FAIL_COND(p_amount < 1); + ERR_FAIL_COND_MSG(p_amount < 1, "Amount of particles cannot be smaller than 1."); amount = p_amount; VS::get_singleton()->particles_set_amount(particles, amount); } void Particles2D::set_lifetime(float p_lifetime) { - ERR_FAIL_COND(p_lifetime <= 0); + ERR_FAIL_COND_MSG(p_lifetime <= 0, "Particles lifetime must be greater than 0."); lifetime = p_lifetime; VS::get_singleton()->particles_set_lifetime(particles, lifetime); } diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index 9b6020e0fd..cea6a782d3 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -199,7 +199,7 @@ void StaticBody2D::set_friction(real_t p_friction) { WARN_DEPRECATED_MSG("The method set_friction has been deprecated and will be removed in the future, use physics material instead."); - ERR_FAIL_COND(p_friction < 0 || p_friction > 1); + ERR_FAIL_COND_MSG(p_friction < 0 || p_friction > 1, "Friction must be between 0 and 1."); if (physics_material_override.is_null()) { physics_material_override.instance(); @@ -227,7 +227,7 @@ void StaticBody2D::set_bounce(real_t p_bounce) { WARN_DEPRECATED_MSG("The method set_bounce has been deprecated and will be removed in the future, use physics material instead."); - ERR_FAIL_COND(p_bounce < 0 || p_bounce > 1); + ERR_FAIL_COND_MSG(p_bounce < 0 || p_bounce > 1, "Bounce must be between 0 and 1."); if (physics_material_override.is_null()) { physics_material_override.instance(); @@ -622,7 +622,7 @@ void RigidBody2D::set_friction(real_t p_friction) { WARN_DEPRECATED_MSG("The method set_friction has been deprecated and will be removed in the future, use physics material instead."); - ERR_FAIL_COND(p_friction < 0 || p_friction > 1); + ERR_FAIL_COND_MSG(p_friction < 0 || p_friction > 1, "Friction must be between 0 and 1."); if (physics_material_override.is_null()) { physics_material_override.instance(); diff --git a/scene/2d/sprite.cpp b/scene/2d/sprite.cpp index d7a8005187..af9ce2a4bf 100644 --- a/scene/2d/sprite.cpp +++ b/scene/2d/sprite.cpp @@ -281,7 +281,7 @@ Vector2 Sprite::get_frame_coords() const { void Sprite::set_vframes(int p_amount) { - ERR_FAIL_COND(p_amount < 1); + ERR_FAIL_COND_MSG(p_amount < 1, "Amount of vframes cannot be smaller than 1."); vframes = p_amount; update(); item_rect_changed(); @@ -294,7 +294,7 @@ int Sprite::get_vframes() const { void Sprite::set_hframes(int p_amount) { - ERR_FAIL_COND(p_amount < 1); + ERR_FAIL_COND_MSG(p_amount < 1, "Amount of hframes cannot be smaller than 1."); hframes = p_amount; update(); item_rect_changed(); diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp index 15423f8c5e..c0c1d8f691 100644 --- a/scene/2d/tile_map.cpp +++ b/scene/2d/tile_map.cpp @@ -216,7 +216,7 @@ Size2 TileMap::get_cell_size() const { void TileMap::set_quadrant_size(int p_size) { - ERR_FAIL_COND(p_size < 1); + ERR_FAIL_COND_MSG(p_size < 1, "Quadrant size cannot be smaller than 1."); _clear_quadrants(); quadrant_size = p_size; diff --git a/scene/3d/baked_lightmap.cpp b/scene/3d/baked_lightmap.cpp index c5ff4dadbc..c78c62a5e2 100644 --- a/scene/3d/baked_lightmap.cpp +++ b/scene/3d/baked_lightmap.cpp @@ -88,7 +88,7 @@ float BakedLightmapData::get_energy() const { void BakedLightmapData::add_user(const NodePath &p_path, const Ref<Texture> &p_lightmap, int p_instance) { - ERR_FAIL_COND(p_lightmap.is_null()); + ERR_FAIL_COND_MSG(p_lightmap.is_null(), "It's not a reference to a valid Texture object."); User user; user.path = p_path; user.lightmap = p_lightmap; @@ -359,7 +359,7 @@ BakedLightmap::BakeError BakedLightmap::bake(Node *p_from_node, bool p_create_vi //check for valid save path DirAccessRef d = DirAccess::open(save_path); if (!d) { - ERR_PRINTS("Invalid Save Path: " + save_path); + ERR_PRINTS("Invalid Save Path '" + save_path + "'."); return BAKE_ERROR_NO_SAVE_PATH; } } diff --git a/scene/3d/cpu_particles.cpp b/scene/3d/cpu_particles.cpp index fc16bc36cb..97688c46b4 100644 --- a/scene/3d/cpu_particles.cpp +++ b/scene/3d/cpu_particles.cpp @@ -53,7 +53,7 @@ void CPUParticles::set_emitting(bool p_emitting) { void CPUParticles::set_amount(int p_amount) { - ERR_FAIL_COND(p_amount < 1); + ERR_FAIL_COND_MSG(p_amount < 1, "Amount of particles must be greater than 0."); particles.resize(p_amount); { @@ -71,7 +71,7 @@ void CPUParticles::set_amount(int p_amount) { } void CPUParticles::set_lifetime(float p_lifetime) { - ERR_FAIL_COND(p_lifetime <= 0); + ERR_FAIL_COND_MSG(p_lifetime <= 0, "Particles lifetime must be greater than 0."); lifetime = p_lifetime; } @@ -1193,7 +1193,7 @@ void CPUParticles::_notification(int p_what) { void CPUParticles::convert_from_particles(Node *p_particles) { Particles *particles = Object::cast_to<Particles>(p_particles); - ERR_FAIL_COND(!particles); + ERR_FAIL_COND_MSG(!particles, "Only Particles nodes can be converted to CPUParticles."); set_emitting(particles->is_emitting()); set_amount(particles->get_amount()); diff --git a/scene/3d/navigation.cpp b/scene/3d/navigation.cpp index 12d562c0c6..ba0460d47c 100644 --- a/scene/3d/navigation.cpp +++ b/scene/3d/navigation.cpp @@ -230,7 +230,7 @@ void Navigation::navmesh_set_transform(int p_id, const Transform &p_xform) { } void Navigation::navmesh_remove(int p_id) { - ERR_FAIL_COND(!navmesh_map.has(p_id)); + ERR_FAIL_COND_MSG(!navmesh_map.has(p_id), "Trying to remove nonexisting navmesh with id: " + itos(p_id)); _navmesh_unlink(p_id); navmesh_map.erase(p_id); } diff --git a/scene/3d/particles.cpp b/scene/3d/particles.cpp index a6ccdb5791..241eb7d1ca 100644 --- a/scene/3d/particles.cpp +++ b/scene/3d/particles.cpp @@ -57,13 +57,13 @@ void Particles::set_emitting(bool p_emitting) { void Particles::set_amount(int p_amount) { - ERR_FAIL_COND(p_amount < 1); + ERR_FAIL_COND_MSG(p_amount < 1, "Amount of particles cannot be smaller than 1."); amount = p_amount; VS::get_singleton()->particles_set_amount(particles, amount); } void Particles::set_lifetime(float p_lifetime) { - ERR_FAIL_COND(p_lifetime <= 0); + ERR_FAIL_COND_MSG(p_lifetime <= 0, "Particles lifetime must be greater than 0."); lifetime = p_lifetime; VS::get_singleton()->particles_set_lifetime(particles, lifetime); } diff --git a/scene/3d/physics_body.cpp b/scene/3d/physics_body.cpp index 0756be5fc8..ea2bb2a21e 100644 --- a/scene/3d/physics_body.cpp +++ b/scene/3d/physics_body.cpp @@ -188,7 +188,7 @@ void StaticBody::set_friction(real_t p_friction) { WARN_DEPRECATED_MSG("The method set_friction has been deprecated and will be removed in the future, use physics material instead."); - ERR_FAIL_COND(p_friction < 0 || p_friction > 1); + ERR_FAIL_COND_MSG(p_friction < 0 || p_friction > 1, "Friction must be between 0 and 1."); if (physics_material_override.is_null()) { physics_material_override.instance(); @@ -216,7 +216,7 @@ void StaticBody::set_bounce(real_t p_bounce) { WARN_DEPRECATED_MSG("The method set_bounce has been deprecated and will be removed in the future, use physics material instead."); - ERR_FAIL_COND(p_bounce < 0 || p_bounce > 1); + ERR_FAIL_COND_MSG(p_bounce < 0 || p_bounce > 1, "Bounce must be between 0 and 1."); if (physics_material_override.is_null()) { physics_material_override.instance(); diff --git a/scene/animation/animation_cache.cpp b/scene/animation/animation_cache.cpp index e26bd5b5a1..5956609244 100644 --- a/scene/animation/animation_cache.cpp +++ b/scene/animation/animation_cache.cpp @@ -80,7 +80,7 @@ void AnimationCache::_update_cache() { if (!node) { path_cache.push_back(Path()); - ERR_CONTINUE_MSG(!node, "Invalid track path in animation: " + np + "."); + ERR_CONTINUE_MSG(!node, "Invalid track path in animation '" + np + "'."); } Path path; @@ -91,7 +91,7 @@ void AnimationCache::_update_cache() { if (np.get_subname_count() > 1) { path_cache.push_back(Path()); - ERR_CONTINUE_MSG(animation->track_get_type(i) == Animation::TYPE_TRANSFORM, "Transform tracks can't have a subpath: " + np + "."); + ERR_CONTINUE_MSG(animation->track_get_type(i) == Animation::TYPE_TRANSFORM, "Transform tracks can't have a subpath '" + np + "'."); } Spatial *sp = Object::cast_to<Spatial>(node); @@ -99,7 +99,7 @@ void AnimationCache::_update_cache() { if (!sp) { path_cache.push_back(Path()); - ERR_CONTINUE_MSG(!sp, "Transform track not of type Spatial: " + np + "."); + ERR_CONTINUE_MSG(!sp, "Transform track not of type Spatial '" + np + "'."); } if (np.get_subname_count() == 1) { @@ -110,13 +110,13 @@ void AnimationCache::_update_cache() { if (!sk) { path_cache.push_back(Path()); - ERR_CONTINUE_MSG(!sk, "Property defined in Transform track, but not a Skeleton!: " + np + "."); + ERR_CONTINUE_MSG(!sk, "Property defined in Transform track, but not a Skeleton! '" + np + "'."); } int idx = sk->find_bone(ps); if (idx == -1) { path_cache.push_back(Path()); - ERR_CONTINUE_MSG(idx == -1, "Property defined in Transform track, but not a Skeleton Bone!: " + np + "."); + ERR_CONTINUE_MSG(idx == -1, "Property defined in Transform track, but not a Skeleton Bone! '" + np + "'."); } path.bone_idx = idx; diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index 051f832882..a31cf0ab39 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -1098,7 +1098,7 @@ void AnimationPlayer::get_animation_list(List<StringName> *p_animations) const { void AnimationPlayer::set_blend_time(const StringName &p_animation1, const StringName &p_animation2, float p_time) { - ERR_FAIL_COND(p_time < 0); + ERR_FAIL_COND_MSG(p_time < 0, "Blend time cannot be smaller than 0."); BlendKey bk; bk.from = p_animation1; diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 7bcef5f9ab..e18442df66 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -6027,7 +6027,7 @@ bool TextEdit::is_indent_using_spaces() const { } void TextEdit::set_indent_size(const int p_size) { - ERR_FAIL_COND(p_size <= 0); + ERR_FAIL_COND_MSG(p_size <= 0, "Indend size must be greater than 0."); indent_size = p_size; text.set_indent_size(p_size); diff --git a/scene/main/node.cpp b/scene/main/node.cpp index bd01ca2886..2eec38fe63 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -2171,7 +2171,7 @@ void Node::_duplicate_and_reown(Node *p_new_parent, const Map<Node *, Node *> &p if (get_filename() != "") { Ref<PackedScene> res = ResourceLoader::load(get_filename()); - ERR_FAIL_COND(res.is_null()); + ERR_FAIL_COND_MSG(res.is_null(), "Cannot load scene: " + get_filename()); node = res->instance(); ERR_FAIL_COND(!node); } else { diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index b5c82ce4e3..04278b2902 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -98,22 +98,22 @@ NodePath ViewportTexture::get_viewport_path_in_scene() const { int ViewportTexture::get_width() const { - ERR_FAIL_COND_V(!vp, 0); + ERR_FAIL_COND_V_MSG(!vp, 0, "Viewport Texture must be set to use it."); return vp->size.width; } int ViewportTexture::get_height() const { - ERR_FAIL_COND_V(!vp, 0); + ERR_FAIL_COND_V_MSG(!vp, 0, "Viewport Texture must be set to use it."); return vp->size.height; } Size2 ViewportTexture::get_size() const { - ERR_FAIL_COND_V(!vp, Size2()); + ERR_FAIL_COND_V_MSG(!vp, Size2(), "Viewport Texture must be set to use it."); return vp->size; } RID ViewportTexture::get_rid() const { - //ERR_FAIL_COND_V(!vp, RID()); + //ERR_FAIL_COND_V_MSG(!vp, RID(), "Viewport Texture must be set to use it."); return proxy; } @@ -123,7 +123,7 @@ bool ViewportTexture::has_alpha() const { } Ref<Image> ViewportTexture::get_data() const { - ERR_FAIL_COND_V(!vp, Ref<Image>()); + ERR_FAIL_COND_V_MSG(!vp, Ref<Image>(), "Viewport Texture must be set to use it."); return VS::get_singleton()->texture_get_data(vp->texture_rid); } void ViewportTexture::set_flags(uint32_t p_flags) { diff --git a/scene/resources/dynamic_font.cpp b/scene/resources/dynamic_font.cpp index 2364a4a8a3..5704212831 100644 --- a/scene/resources/dynamic_font.cpp +++ b/scene/resources/dynamic_font.cpp @@ -130,7 +130,7 @@ Error DynamicFontAtSize::_load() { } else { FileAccess *f = FileAccess::open(font->font_path, FileAccess::READ); - ERR_FAIL_COND_V(!f, ERR_CANT_OPEN); + ERR_FAIL_COND_V_MSG(!f, ERR_CANT_OPEN, "Cannot open font file '" + font->font_path + "'."); size_t len = f->get_len(); _fontdata[font->font_path] = Vector<uint8_t>(); @@ -145,7 +145,7 @@ Error DynamicFontAtSize::_load() { if (font->font_mem == NULL && font->font_path != String()) { FileAccess *f = FileAccess::open(font->font_path, FileAccess::READ); - ERR_FAIL_COND_V(!f, ERR_CANT_OPEN); + ERR_FAIL_COND_V_MSG(!f, ERR_CANT_OPEN, "Cannot open font file '" + font->font_path + "'."); memset(&stream, 0, sizeof(FT_StreamRec)); stream.base = NULL; @@ -182,17 +182,16 @@ Error DynamicFontAtSize::_load() { //error = FT_New_Face( library, src_path.utf8().get_data(),0,&face ); if (error == FT_Err_Unknown_File_Format) { - ERR_EXPLAIN("Unknown font format."); + FT_Done_FreeType(library); + ERR_FAIL_V_MSG(ERR_FILE_CANT_OPEN, "Unknown font format."); } else if (error) { - ERR_EXPLAIN("Error loading font."); FT_Done_FreeType(library); + ERR_FAIL_V_MSG(ERR_FILE_CANT_OPEN, "Error loading font."); } - ERR_FAIL_COND_V(error, ERR_FILE_CANT_OPEN); - if (FT_HAS_COLOR(face)) { int best_match = 0; int diff = ABS(id.size - ((int64_t)face->available_sizes[0].width)); diff --git a/scene/resources/dynamic_font_stb.cpp b/scene/resources/dynamic_font_stb.cpp index ccff617a16..412bffa5dc 100644 --- a/scene/resources/dynamic_font_stb.cpp +++ b/scene/resources/dynamic_font_stb.cpp @@ -480,7 +480,7 @@ RES ResourceFormatLoaderDynamicFont::load(const String &p_path, const String &p_ *r_error = ERR_FILE_CANT_OPEN; FileAccess *f = FileAccess::open(p_path, FileAccess::READ); - ERR_FAIL_COND_V(!f, RES()); + ERR_FAIL_COND_V_MSG(!f, RES(), "Cannot load font from file '" + p_path + "'."); PoolVector<uint8_t> data; diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp index cff77acdd7..c94e143580 100644 --- a/scene/resources/font.cpp +++ b/scene/resources/font.cpp @@ -358,7 +358,7 @@ float BitmapFont::get_descent() const { void BitmapFont::add_texture(const Ref<Texture> &p_texture) { - ERR_FAIL_COND(p_texture.is_null()); + ERR_FAIL_COND_MSG(p_texture.is_null(), "It's not a reference to a valid Texture object."); textures.push_back(p_texture); } diff --git a/scene/resources/mesh_library.cpp b/scene/resources/mesh_library.cpp index d40a5dee2e..ad8da63abf 100644 --- a/scene/resources/mesh_library.cpp +++ b/scene/resources/mesh_library.cpp @@ -117,7 +117,7 @@ void MeshLibrary::create_item(int p_item) { void MeshLibrary::set_item_name(int p_item, const String &p_name) { - ERR_FAIL_COND(!item_map.has(p_item)); + ERR_FAIL_COND_MSG(!item_map.has(p_item), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'."); item_map[p_item].name = p_name; emit_changed(); _change_notify(); @@ -125,7 +125,7 @@ void MeshLibrary::set_item_name(int p_item, const String &p_name) { void MeshLibrary::set_item_mesh(int p_item, const Ref<Mesh> &p_mesh) { - ERR_FAIL_COND(!item_map.has(p_item)); + ERR_FAIL_COND_MSG(!item_map.has(p_item), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'."); item_map[p_item].mesh = p_mesh; notify_change_to_owners(); emit_changed(); @@ -134,7 +134,7 @@ void MeshLibrary::set_item_mesh(int p_item, const Ref<Mesh> &p_mesh) { void MeshLibrary::set_item_shapes(int p_item, const Vector<ShapeData> &p_shapes) { - ERR_FAIL_COND(!item_map.has(p_item)); + ERR_FAIL_COND_MSG(!item_map.has(p_item), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'."); item_map[p_item].shapes = p_shapes; _change_notify(); notify_change_to_owners(); @@ -144,7 +144,7 @@ void MeshLibrary::set_item_shapes(int p_item, const Vector<ShapeData> &p_shapes) void MeshLibrary::set_item_navmesh(int p_item, const Ref<NavigationMesh> &p_navmesh) { - ERR_FAIL_COND(!item_map.has(p_item)); + ERR_FAIL_COND_MSG(!item_map.has(p_item), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'."); item_map[p_item].navmesh = p_navmesh; _change_notify(); notify_change_to_owners(); @@ -154,7 +154,7 @@ void MeshLibrary::set_item_navmesh(int p_item, const Ref<NavigationMesh> &p_navm void MeshLibrary::set_item_navmesh_transform(int p_item, const Transform &p_transform) { - ERR_FAIL_COND(!item_map.has(p_item)); + ERR_FAIL_COND_MSG(!item_map.has(p_item), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'."); item_map[p_item].navmesh_transform = p_transform; notify_change_to_owners(); emit_changed(); @@ -163,7 +163,7 @@ void MeshLibrary::set_item_navmesh_transform(int p_item, const Transform &p_tran void MeshLibrary::set_item_preview(int p_item, const Ref<Texture> &p_preview) { - ERR_FAIL_COND(!item_map.has(p_item)); + ERR_FAIL_COND_MSG(!item_map.has(p_item), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'."); item_map[p_item].preview = p_preview; emit_changed(); _change_notify(); @@ -171,37 +171,37 @@ void MeshLibrary::set_item_preview(int p_item, const Ref<Texture> &p_preview) { String MeshLibrary::get_item_name(int p_item) const { - ERR_FAIL_COND_V(!item_map.has(p_item), ""); + ERR_FAIL_COND_V_MSG(!item_map.has(p_item), "", "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'."); return item_map[p_item].name; } Ref<Mesh> MeshLibrary::get_item_mesh(int p_item) const { - ERR_FAIL_COND_V(!item_map.has(p_item), Ref<Mesh>()); + ERR_FAIL_COND_V_MSG(!item_map.has(p_item), Ref<Mesh>(), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'."); return item_map[p_item].mesh; } Vector<MeshLibrary::ShapeData> MeshLibrary::get_item_shapes(int p_item) const { - ERR_FAIL_COND_V(!item_map.has(p_item), Vector<ShapeData>()); + ERR_FAIL_COND_V_MSG(!item_map.has(p_item), Vector<ShapeData>(), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'."); return item_map[p_item].shapes; } Ref<NavigationMesh> MeshLibrary::get_item_navmesh(int p_item) const { - ERR_FAIL_COND_V(!item_map.has(p_item), Ref<NavigationMesh>()); + ERR_FAIL_COND_V_MSG(!item_map.has(p_item), Ref<NavigationMesh>(), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'."); return item_map[p_item].navmesh; } Transform MeshLibrary::get_item_navmesh_transform(int p_item) const { - ERR_FAIL_COND_V(!item_map.has(p_item), Transform()); + ERR_FAIL_COND_V_MSG(!item_map.has(p_item), Transform(), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'."); return item_map[p_item].navmesh_transform; } Ref<Texture> MeshLibrary::get_item_preview(int p_item) const { - ERR_FAIL_COND_V(!item_map.has(p_item), Ref<Texture>()); + ERR_FAIL_COND_V_MSG(!item_map.has(p_item), Ref<Texture>(), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'."); return item_map[p_item].preview; } @@ -211,7 +211,7 @@ bool MeshLibrary::has_item(int p_item) const { } void MeshLibrary::remove_item(int p_item) { - ERR_FAIL_COND(!item_map.has(p_item)); + ERR_FAIL_COND_MSG(!item_map.has(p_item), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'."); item_map.erase(p_item); notify_change_to_owners(); _change_notify(); diff --git a/scene/resources/resource_format_text.cpp b/scene/resources/resource_format_text.cpp index cd229732ba..89712db9f4 100644 --- a/scene/resources/resource_format_text.cpp +++ b/scene/resources/resource_format_text.cpp @@ -1225,7 +1225,7 @@ Ref<ResourceInteractiveLoader> ResourceFormatLoaderText::load_interactive(const Error err; FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err); - ERR_FAIL_COND_V(err != OK, Ref<ResourceInteractiveLoader>()); + ERR_FAIL_COND_V_MSG(err != OK, Ref<ResourceInteractiveLoader>(), "Cannot open file '" + p_path + "'."); Ref<ResourceInteractiveLoaderText> ria = memnew(ResourceInteractiveLoaderText); String path = p_original_path != "" ? p_original_path : p_path; @@ -1321,7 +1321,7 @@ Error ResourceFormatLoaderText::convert_file_to_binary(const String &p_src_path, Error err; FileAccess *f = FileAccess::open(p_src_path, FileAccess::READ, &err); - ERR_FAIL_COND_V(err != OK, ERR_CANT_OPEN); + ERR_FAIL_COND_V_MSG(err != OK, ERR_CANT_OPEN, "Cannot open file '" + p_src_path + "'."); Ref<ResourceInteractiveLoaderText> ria = memnew(ResourceInteractiveLoaderText); const String &path = p_src_path; @@ -1481,7 +1481,7 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r Error err; f = FileAccess::open(p_path, FileAccess::WRITE, &err); - ERR_FAIL_COND_V(err, ERR_CANT_OPEN); + ERR_FAIL_COND_V_MSG(err, ERR_CANT_OPEN, "Cannot save file '" + p_path + "'."); FileAccessRef _fref(f); local_path = ProjectSettings::get_singleton()->localize_path(p_path); diff --git a/scene/resources/shader.cpp b/scene/resources/shader.cpp index 89570beb5f..57e2470164 100644 --- a/scene/resources/shader.cpp +++ b/scene/resources/shader.cpp @@ -222,10 +222,7 @@ Error ResourceFormatSaverShader::save(const String &p_path, const RES &p_resourc Error err; FileAccess *file = FileAccess::open(p_path, FileAccess::WRITE, &err); - if (err) { - - ERR_FAIL_COND_V(err, err); - } + ERR_FAIL_COND_V_MSG(err, err, "Cannot save shader '" + p_path + "'."); file->store_string(source); if (file->get_error() != OK && file->get_error() != ERR_FILE_EOF) { diff --git a/scene/resources/text_file.cpp b/scene/resources/text_file.cpp index b84f3f1f9e..3faedc883d 100644 --- a/scene/resources/text_file.cpp +++ b/scene/resources/text_file.cpp @@ -53,9 +53,8 @@ Error TextFile::load_text(const String &p_path) { PoolVector<uint8_t> sourcef; Error err; FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err); - if (err) { - ERR_FAIL_COND_V(err, err); - } + + ERR_FAIL_COND_V_MSG(err, err, "Cannot open TextFile '" + p_path + "'."); int len = f->get_len(); sourcef.resize(len + 1); diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index e44b17584b..d15a972358 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -175,7 +175,7 @@ void ImageTexture::_reload_hook(const RID &p_hook) { img.instance(); Error err = ImageLoader::load_image(path, img); - ERR_FAIL_COND(err != OK); + ERR_FAIL_COND_MSG(err != OK, "Cannot load image from path '" + path + "'."); VisualServer::get_singleton()->texture_set_data(texture, img); @@ -2355,7 +2355,7 @@ RES ResourceFormatLoaderTextureLayered::load(const String &p_path, const String } FileAccess *f = FileAccess::open(p_path, FileAccess::READ); - ERR_FAIL_COND_V(!f, RES()); + ERR_FAIL_COND_V_MSG(!f, RES(), "Cannot open file '" + p_path + "'."); uint8_t header[5] = { 0, 0, 0, 0, 0 }; f->get_buffer(header, 4); @@ -2372,7 +2372,7 @@ RES ResourceFormatLoaderTextureLayered::load(const String &p_path, const String } } else { - ERR_FAIL_V_MSG(RES(), "Unrecognized layered texture file format: " + String((const char *)header) + "."); + ERR_FAIL_V_MSG(RES(), "Unrecognized layered texture file format '" + String((const char *)header) + "'."); } int tw = f->get_32(); diff --git a/servers/physics/collision_object_sw.h b/servers/physics/collision_object_sw.h index b9912f0ba2..08708e2f60 100644 --- a/servers/physics/collision_object_sw.h +++ b/servers/physics/collision_object_sw.h @@ -88,7 +88,7 @@ protected: _FORCE_INLINE_ void _set_transform(const Transform &p_transform, bool p_update_shapes = true) { #ifdef DEBUG_ENABLED - ERR_FAIL_COND_MSG(p_transform.origin.length_squared() > MAX_OBJECT_DISTANCE_X2, "Object went too far away (more than " + itos(MAX_OBJECT_DISTANCE) + " units from origin)."); + ERR_FAIL_COND_MSG(p_transform.origin.length_squared() > MAX_OBJECT_DISTANCE_X2, "Object went too far away (more than '" + itos(MAX_OBJECT_DISTANCE) + "' units from origin)."); #endif transform = p_transform; |