diff --git a/core/array.cpp b/core/array.cpp index a334af2c044..108d9f7386e 100644 --- a/core/array.cpp +++ b/core/array.cpp @@ -133,18 +133,12 @@ void Array::erase(const Variant &p_value) { } Variant Array::front() const { - if (_p->array.size() == 0) { - ERR_EXPLAIN("Can't take value from empty array"); - ERR_FAIL_V(Variant()); - } + ERR_FAIL_COND_V_MSG(_p->array.size() == 0, Variant(), "Can't take value from empty array."); return operator[](0); } Variant Array::back() const { - if (_p->array.size() == 0) { - ERR_EXPLAIN("Can't take value from empty array"); - ERR_FAIL_V(Variant()); - } + ERR_FAIL_COND_V_MSG(_p->array.size() == 0, Variant(), "Can't take value from empty array."); return operator[](_p->array.size() - 1); } diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index b41b84ab1e5..56369a3cc62 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -73,10 +73,7 @@ RES _ResourceLoader::load(const String &p_path, const String &p_type_hint, bool Error err = OK; RES ret = ResourceLoader::load(p_path, p_type_hint, p_no_cache, &err); - if (err != OK) { - ERR_EXPLAIN("Error loading resource: '" + p_path + "'"); - ERR_FAIL_V(ret); - } + ERR_FAIL_COND_V_MSG(err != OK, ret, "Error loading resource: '" + p_path + "'."); return ret; } @@ -148,10 +145,7 @@ _ResourceLoader::_ResourceLoader() { } Error _ResourceSaver::save(const String &p_path, const RES &p_resource, SaverFlags p_flags) { - if (p_resource.is_null()) { - ERR_EXPLAIN("Can't save empty resource to path: " + String(p_path)) - ERR_FAIL_V(ERR_INVALID_PARAMETER); - } + 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); } @@ -727,22 +721,16 @@ int64_t _OS::get_unix_time_from_datetime(Dictionary datetime) const { { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 } }; - ERR_EXPLAIN("Invalid second value of: " + itos(second)); - ERR_FAIL_COND_V(second > 59, 0); + ERR_FAIL_COND_V_MSG(second > 59, 0, "Invalid second value of: " + itos(second) + "."); - ERR_EXPLAIN("Invalid minute value of: " + itos(minute)); - ERR_FAIL_COND_V(minute > 59, 0); + ERR_FAIL_COND_V_MSG(minute > 59, 0, "Invalid minute value of: " + itos(minute) + "."); - ERR_EXPLAIN("Invalid hour value of: " + itos(hour)); - ERR_FAIL_COND_V(hour > 23, 0); + ERR_FAIL_COND_V_MSG(hour > 23, 0, "Invalid hour value of: " + itos(hour) + "."); - ERR_EXPLAIN("Invalid month value of: " + itos(month)); - ERR_FAIL_COND_V(month > 12 || month == 0, 0); + 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_EXPLAIN("Invalid day value of: " + itos(day) + " which is larger than " + itos(MONTH_DAYS_TABLE[LEAPYEAR(year)][month - 1]) + " or 0"); - ERR_FAIL_COND_V(day > MONTH_DAYS_TABLE[LEAPYEAR(year)][month - 1] || day == 0, 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; @@ -2621,8 +2609,7 @@ void _Thread::_start_func(void *ud) { } } - ERR_EXPLAIN("Could not call function '" + t->target_method.operator String() + "'' starting thread ID: " + t->get_id() + " Reason: " + reason); - ERR_FAIL(); + ERR_FAIL_MSG("Could not call function '" + t->target_method.operator String() + "'' starting thread ID: " + t->get_id() + " Reason: " + reason + "."); } } @@ -2704,10 +2691,7 @@ _Thread::_Thread() { _Thread::~_Thread() { - if (active) { - ERR_EXPLAIN("Reference to a Thread object object was lost while the thread is still running..."); - } - ERR_FAIL_COND(active); + ERR_FAIL_COND_MSG(active, "Reference to a Thread object object was lost while the thread is still running..."); } ///////////////////////////////////// diff --git a/core/class_db.cpp b/core/class_db.cpp index 49e3f94d8f2..3ad59bc3099 100644 --- a/core/class_db.cpp +++ b/core/class_db.cpp @@ -836,10 +836,7 @@ void ClassDB::add_signal(StringName p_class, const MethodInfo &p_signal) { #ifdef DEBUG_METHODS_ENABLED ClassInfo *check = type; while (check) { - if (check->signal_map.has(sname)) { - ERR_EXPLAIN("Type " + String(p_class) + " already has signal: " + String(sname)); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(check->signal_map.has(sname), "Type " + String(p_class) + " already has signal: " + String(sname) + "."); check = check->inherits_ptr; } #endif @@ -924,16 +921,11 @@ void ClassDB::add_property(StringName p_class, const PropertyInfo &p_pinfo, cons if (p_setter) { mb_set = get_method(p_class, p_setter); #ifdef DEBUG_METHODS_ENABLED - if (!mb_set) { - ERR_EXPLAIN("Invalid Setter: " + p_class + "::" + p_setter + " for property: " + p_pinfo.name); - ERR_FAIL(); - } else { - int exp_args = 1 + (p_index >= 0 ? 1 : 0); - if (mb_set->get_argument_count() != exp_args) { - ERR_EXPLAIN("Invalid Function for Setter: " + p_class + "::" + p_setter + " for property: " + p_pinfo.name); - ERR_FAIL(); - } - } + + 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 + "."); #endif } @@ -943,25 +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 - if (!mb_get) { - ERR_EXPLAIN("Invalid Getter: " + p_class + "::" + p_getter + " for property: " + p_pinfo.name); - ERR_FAIL(); - } else { + 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); - if (mb_get->get_argument_count() != exp_args) { - ERR_EXPLAIN("Invalid Function for Getter: " + p_class + "::" + p_getter + " for property: " + p_pinfo.name); - ERR_FAIL(); - } - } + 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 + "."); #endif } #ifdef DEBUG_METHODS_ENABLED - if (type->property_setget.has(p_pinfo.name)) { - ERR_EXPLAIN("Object " + p_class + " already has property: " + p_pinfo.name); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(type->property_setget.has(p_pinfo.name), "Object " + p_class + " already has property: " + p_pinfo.name + "."); #endif OBJTYPE_WLOCK @@ -1240,32 +1222,26 @@ MethodBind *ClassDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind, const c #ifdef DEBUG_ENABLED - if (has_method(instance_type, mdname)) { - ERR_EXPLAIN("Class " + String(instance_type) + " already has a method " + String(mdname)); - ERR_FAIL_V(NULL); - } + ERR_FAIL_COND_V_MSG(has_method(instance_type, mdname), NULL, "Class " + String(instance_type) + " already has a method " + String(mdname) + "."); #endif ClassInfo *type = classes.getptr(instance_type); if (!type) { - ERR_PRINTS("Couldn't bind method '" + mdname + "' for instance: " + instance_type); memdelete(p_bind); - ERR_FAIL_V(NULL); + 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_EXPLAIN("Method already bound: " + instance_type + "::" + mdname); - ERR_FAIL_V(NULL); + 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_EXPLAIN("Method definition provides more arguments than the method actually has: " + instance_type + "::" + mdname); - ERR_FAIL_V(NULL); + 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); diff --git a/core/class_db.h b/core/class_db.h index 3864522be4e..092469beb7e 100644 --- a/core/class_db.h +++ b/core/class_db.h @@ -306,8 +306,7 @@ public: if (type->method_map.has(p_name)) { memdelete(bind); // overloading not supported - ERR_EXPLAIN("Method already bound: " + instance_type + "::" + p_name); - ERR_FAIL_V(NULL); + ERR_FAIL_V_MSG(NULL, "Method already bound: " + instance_type + "::" + p_name + "."); } type->method_map[p_name] = bind; #ifdef DEBUG_METHODS_ENABLED diff --git a/core/color.cpp b/core/color.cpp index 18435321243..a54a3115ccd 100644 --- a/core/color.cpp +++ b/core/color.cpp @@ -335,36 +335,23 @@ Color Color::html(const String &p_color) { } else if (color.length() == 6) { alpha = false; } else { - ERR_EXPLAIN("Invalid Color Code: " + p_color); - ERR_FAIL_V(Color()); + ERR_FAIL_V_MSG(Color(), "Invalid color code: " + p_color + "."); } int a = 255; if (alpha) { a = _parse_col(color, 0); - if (a < 0) { - ERR_EXPLAIN("Invalid Color Code: " + p_color); - ERR_FAIL_V(Color()); - } + ERR_FAIL_COND_V_MSG(a < 0, Color(), "Invalid color code: " + p_color + "."); } int from = alpha ? 2 : 0; int r = _parse_col(color, from + 0); - if (r < 0) { - ERR_EXPLAIN("Invalid Color Code: " + p_color); - ERR_FAIL_V(Color()); - } + ERR_FAIL_COND_V_MSG(r < 0, Color(), "Invalid color code: " + p_color + "."); int g = _parse_col(color, from + 2); - if (g < 0) { - ERR_EXPLAIN("Invalid Color Code: " + p_color); - ERR_FAIL_V(Color()); - } + ERR_FAIL_COND_V_MSG(g < 0, Color(), "Invalid color code: " + p_color + "."); int b = _parse_col(color, from + 4); - if (b < 0) { - ERR_EXPLAIN("Invalid Color Code: " + p_color); - ERR_FAIL_V(Color()); - } + ERR_FAIL_COND_V_MSG(b < 0, Color(), "Invalid color code: " + p_color + "."); return Color(r / 255.0, g / 255.0, b / 255.0, a / 255.0); } @@ -425,12 +412,8 @@ Color Color::named(const String &p_name) { name = name.to_lower(); const Map::Element *color = _named_colors.find(name); - if (color) { - return color->value(); - } else { - ERR_EXPLAIN("Invalid Color Name: " + p_name); - ERR_FAIL_V(Color()); - } + ERR_FAIL_NULL_V_MSG(color, Color(), "Invalid color name: " + p_name + "."); + return color->value(); } String _to_hex(float p_val) { @@ -523,8 +506,7 @@ Color Color::from_hsv(float p_h, float p_s, float p_v, float p_a) const { // FIXME: Remove once Godot 3.1 has been released float Color::gray() const { - ERR_EXPLAIN("Color.gray() is deprecated and will be removed in a future version. Use Color.get_v() for a better grayscale approximation."); - WARN_DEPRECATED; + WARN_DEPRECATED_MSG("Color.gray() is deprecated and will be removed in a future version. Use Color.get_v() for a better grayscale approximation."); return (r + g + b) / 3.0; } diff --git a/core/engine.cpp b/core/engine.cpp index 0dd0459403b..937439faaf5 100644 --- a/core/engine.cpp +++ b/core/engine.cpp @@ -197,10 +197,7 @@ void Engine::add_singleton(const Singleton &p_singleton) { Object *Engine::get_singleton_object(const String &p_name) const { const Map::Element *E = singleton_ptrs.find(p_name); - if (!E) { - ERR_EXPLAIN("Failed to retrieve non-existent singleton '" + p_name + "'"); - ERR_FAIL_V(NULL); - } + ERR_FAIL_COND_V_MSG(!E, NULL, "Failed to retrieve non-existent singleton '" + p_name + "'."); return E->get(); }; diff --git a/core/hash_map.h b/core/hash_map.h index 1513d7a65b4..81ddc376d04 100644 --- a/core/hash_map.h +++ b/core/hash_map.h @@ -151,11 +151,7 @@ private: return; Element **new_hash_table = memnew_arr(Element *, ((uint64_t)1 << new_hash_table_power)); - if (!new_hash_table) { - - ERR_PRINT("Out of Memory"); - return; - } + ERR_FAIL_COND_MSG(!new_hash_table, "Out of memory."); for (int i = 0; i < (1 << new_hash_table_power); i++) { @@ -208,10 +204,7 @@ private: /* if element doesn't exist, create it */ Element *e = memnew(Element); - if (!e) { - ERR_EXPLAIN("Out of memory"); - ERR_FAIL_V(NULL); - } + ERR_FAIL_COND_V_MSG(!e, NULL, "Out of memory."); uint32_t hash = Hasher::hash(p_key); uint32_t index = hash & ((1 << hash_table_power) - 1); e->next = hash_table[index]; @@ -498,10 +491,7 @@ public: } else { /* get the next key */ const Element *e = get_element(*p_key); - if (!e) { - ERR_EXPLAIN("Invalid key supplied") - ERR_FAIL_V(NULL); - } + ERR_FAIL_COND_V_MSG(!e, NULL, "Invalid key supplied."); if (e->next) { /* if there is a "next" in the list, return that */ return &e->next->pair.key; diff --git a/core/image.cpp b/core/image.cpp index 6211c06ebe3..d8d667dbd50 100644 --- a/core/image.cpp +++ b/core/image.cpp @@ -423,8 +423,7 @@ void Image::convert(Format p_new_format) { if (format > FORMAT_RGBE9995 || p_new_format > FORMAT_RGBE9995) { - ERR_EXPLAIN("Cannot convert to <-> from compressed formats. Use compress() and decompress() instead."); - ERR_FAIL(); + ERR_FAIL_MSG("Cannot convert to <-> from compressed formats. Use compress() and decompress() instead."); } else if (format > FORMAT_RGBA8 || p_new_format > FORMAT_RGBA8) { @@ -864,10 +863,7 @@ bool Image::is_size_po2() const { void Image::resize_to_po2(bool p_square) { - if (!_can_modify(format)) { - ERR_EXPLAIN("Cannot resize in indexed, compressed or custom image formats."); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!_can_modify(format), "Cannot resize in indexed, compressed or custom image formats."); int w = next_power_of_2(width); int h = next_power_of_2(height); @@ -883,15 +879,9 @@ void Image::resize_to_po2(bool p_square) { void Image::resize(int p_width, int p_height, Interpolation p_interpolation) { - if (data.size() == 0) { - ERR_EXPLAIN("Cannot resize image before creating it, use create() or create_from_data() first."); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(data.size() == 0, "Cannot resize image before creating it, use create() or create_from_data() first."); - if (!_can_modify(format)) { - ERR_EXPLAIN("Cannot resize in indexed, compressed or custom image formats."); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!_can_modify(format), "Cannot resize in indexed, compressed or custom image formats."); bool mipmap_aware = p_interpolation == INTERPOLATE_TRILINEAR /* || p_interpolation == INTERPOLATE_TRICUBIC */; @@ -1104,10 +1094,8 @@ void Image::resize(int p_width, int p_height, Interpolation p_interpolation) { void Image::crop_from_point(int p_x, int p_y, int p_width, int p_height) { - if (!_can_modify(format)) { - ERR_EXPLAIN("Cannot crop in indexed, compressed or custom image formats."); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!_can_modify(format), "Cannot crop in indexed, compressed or custom image formats."); + ERR_FAIL_COND(p_x < 0); ERR_FAIL_COND(p_y < 0); ERR_FAIL_COND(p_width <= 0); @@ -1161,10 +1149,7 @@ void Image::crop(int p_width, int p_height) { void Image::flip_y() { - if (!_can_modify(format)) { - ERR_EXPLAIN("Cannot flip_y in indexed, compressed or custom image formats."); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!_can_modify(format), "Cannot flip_y in indexed, compressed or custom image formats."); bool used_mipmaps = has_mipmaps(); if (used_mipmaps) { @@ -1197,10 +1182,7 @@ void Image::flip_y() { void Image::flip_x() { - if (!_can_modify(format)) { - ERR_EXPLAIN("Cannot flip_x in indexed, compressed or custom image formats."); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!_can_modify(format), "Cannot flip_x in indexed, compressed or custom image formats."); bool used_mipmaps = has_mipmaps(); if (used_mipmaps) { @@ -1459,15 +1441,9 @@ void Image::normalize() { Error Image::generate_mipmaps(bool p_renormalize) { - if (!_can_modify(format)) { - ERR_EXPLAIN("Cannot generate mipmaps in indexed, compressed or custom image formats."); - ERR_FAIL_V(ERR_UNAVAILABLE); - } + ERR_FAIL_COND_V_MSG(!_can_modify(format), ERR_UNAVAILABLE, "Cannot generate mipmaps in indexed, compressed or custom image formats."); - if (width == 0 || height == 0) { - ERR_EXPLAIN("Cannot generate mipmaps with width or height equal to 0."); - ERR_FAIL_V(ERR_UNCONFIGURED); - } + ERR_FAIL_COND_V_MSG(width == 0 || height == 0, ERR_UNCONFIGURED, "Cannot generate mipmaps with width or height equal to 0."); int mmcount; @@ -1618,10 +1594,7 @@ void Image::create(int p_width, int p_height, bool p_use_mipmaps, Format p_forma int mm; int size = _get_dst_image_size(p_width, p_height, p_format, mm, p_use_mipmaps ? -1 : 0); - if (size != p_data.size()) { - ERR_EXPLAIN("Expected data size of " + itos(size) + " bytes in Image::create(), got instead " + itos(p_data.size()) + " bytes."); - ERR_FAIL_COND(p_data.size() != size); - } + ERR_FAIL_COND_MSG(p_data.size() != size, "Expected data size of " + itos(size) + " bytes in Image::create(), got instead " + itos(p_data.size()) + " bytes."); height = p_height; width = p_width; @@ -2411,10 +2384,7 @@ Color Image::get_pixel(int p_x, int p_y) const { uint8_t *ptr = write_lock.ptr(); #ifdef DEBUG_ENABLED - if (!ptr) { - ERR_EXPLAIN("Image must be locked with 'lock()' before using get_pixel()"); - ERR_FAIL_V(Color()); - } + ERR_FAIL_COND_V_MSG(!ptr, Color(), "Image must be locked with 'lock()' before using get_pixel()."); ERR_FAIL_INDEX_V(p_x, width, Color()); ERR_FAIL_INDEX_V(p_y, height, Color()); @@ -2530,8 +2500,7 @@ Color Image::get_pixel(int p_x, int p_y) const { return Color::from_rgbe9995(((uint32_t *)ptr)[ofs]); } default: { - ERR_EXPLAIN("Can't get_pixel() on compressed image, sorry."); - ERR_FAIL_V(Color()); + ERR_FAIL_V_MSG(Color(), "Can't get_pixel() on compressed image, sorry."); } } } @@ -2544,10 +2513,7 @@ void Image::set_pixel(int p_x, int p_y, const Color &p_color) { uint8_t *ptr = write_lock.ptr(); #ifdef DEBUG_ENABLED - if (!ptr) { - ERR_EXPLAIN("Image must be locked with 'lock()' before using set_pixel()"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!ptr, "Image must be locked with 'lock()' before using set_pixel()."); ERR_FAIL_INDEX(p_x, width); ERR_FAIL_INDEX(p_y, height); @@ -2659,8 +2625,7 @@ void Image::set_pixel(int p_x, int p_y, const Color &p_color) { } break; default: { - ERR_EXPLAIN("Can't set_pixel() on compressed image, sorry."); - ERR_FAIL(); + ERR_FAIL_MSG("Can't set_pixel() on compressed image, sorry."); } } } diff --git a/core/input_map.cpp b/core/input_map.cpp index 165999f0811..2a8ac435fe3 100644 --- a/core/input_map.cpp +++ b/core/input_map.cpp @@ -192,10 +192,7 @@ bool InputMap::event_is_action(const Ref &p_event, const StringName bool InputMap::event_get_action_status(const Ref &p_event, const StringName &p_action, bool *p_pressed, float *p_strength) const { Map::Element *E = input_map.find(p_action); - if (!E) { - ERR_EXPLAIN("Request for nonexistent InputMap action: " + String(p_action)); - ERR_FAIL_V(false); - } + ERR_FAIL_COND_V_MSG(!E, false, "Request for nonexistent InputMap action: " + String(p_action) + "."); Ref input_event_action = p_event; if (input_event_action.is_valid()) { diff --git a/core/io/config_file.cpp b/core/io/config_file.cpp index f7fb72c0899..70bb816acd6 100644 --- a/core/io/config_file.cpp +++ b/core/io/config_file.cpp @@ -86,10 +86,7 @@ void ConfigFile::set_value(const String &p_section, const String &p_key, const V Variant ConfigFile::get_value(const String &p_section, const String &p_key, Variant p_default) const { if (!values.has(p_section) || !values[p_section].has(p_key)) { - if (p_default.get_type() == Variant::NIL) { - ERR_EXPLAIN("Couldn't find the given section/key and no default was given"); - ERR_FAIL_V(p_default); - } + ERR_FAIL_COND_V_MSG(p_default.get_type() == Variant::NIL, p_default, "Couldn't find the given section/key and no default was given."); return p_default; } return values[p_section][p_key]; @@ -271,7 +268,7 @@ Error ConfigFile::_internal_load(const String &p_path, FileAccess *f) { memdelete(f); return OK; } else if (err != OK) { - ERR_PRINTS("ConfgFile::load - " + p_path + ":" + itos(lines) + " error: " + error_text); + ERR_PRINTS("ConfgFile::load - " + p_path + ":" + itos(lines) + " error: " + error_text + "."); memdelete(f); return err; } diff --git a/core/io/file_access_buffered.cpp b/core/io/file_access_buffered.cpp index 15523a49a91..f72ad61da6a 100644 --- a/core/io/file_access_buffered.cpp +++ b/core/io/file_access_buffered.cpp @@ -87,10 +87,8 @@ bool FileAccessBuffered::eof_reached() const { } uint8_t FileAccessBuffered::get_8() const { - if (!file.open) { - ERR_EXPLAIN("Can't get data, when file is not opened."); - ERR_FAIL_V(0); - } + + ERR_FAIL_COND_V_MSG(!file.open, 0, "Can't get data, when file is not opened."); uint8_t byte = 0; if (cache_data_left() >= 1) { @@ -104,10 +102,8 @@ uint8_t FileAccessBuffered::get_8() const { } int FileAccessBuffered::get_buffer(uint8_t *p_dest, int p_length) const { - if (!file.open) { - ERR_EXPLAIN("Can't get buffer, when file is not opened."); - ERR_FAIL_V(-1); - } + + ERR_FAIL_COND_V_MSG(!file.open, -1, "Can't get buffer, when file is not opened."); if (p_length > cache_size) { diff --git a/core/io/file_access_encrypted.cpp b/core/io/file_access_encrypted.cpp index ccee6aeb157..1452c61d1ad 100644 --- a/core/io/file_access_encrypted.cpp +++ b/core/io/file_access_encrypted.cpp @@ -94,8 +94,7 @@ Error FileAccessEncrypted::open_and_parse(FileAccess *p_base, const Vectorget_32(); f->get_32(); // ver_rev - ERR_EXPLAIN("Pack version unsupported: " + itos(version)); - ERR_FAIL_COND_V(version != PACK_VERSION, false); - ERR_EXPLAIN("Pack created with a newer version of the engine: " + itos(ver_major) + "." + itos(ver_minor)); - ERR_FAIL_COND_V(ver_major > VERSION_MAJOR || (ver_major == VERSION_MAJOR && ver_minor > VERSION_MINOR), false); + ERR_FAIL_COND_V_MSG(version != PACK_VERSION, false, "Pack version unsupported: " + itos(version) + "."); + ERR_FAIL_COND_V_MSG(ver_major > VERSION_MAJOR || (ver_major == VERSION_MAJOR && ver_minor > VERSION_MINOR), false, "Pack created with a newer version of the engine: " + itos(ver_major) + "." + itos(ver_minor) + "."); for (int i = 0; i < 16; i++) { //reserved @@ -322,10 +320,9 @@ bool FileAccessPack::file_exists(const String &p_name) { FileAccessPack::FileAccessPack(const String &p_path, const PackedData::PackedFile &p_file) : pf(p_file), f(FileAccess::open(pf.pack, FileAccess::READ)) { - if (!f) { - ERR_EXPLAIN("Can't open pack-referenced file: " + String(pf.pack)); - ERR_FAIL_COND(!f); - } + + ERR_FAIL_COND_MSG(!f, "Can't open pack-referenced file: " + String(pf.pack) + "."); + f->seek(pf.offset); pos = 0; eof = false; diff --git a/core/io/ip_address.cpp b/core/io/ip_address.cpp index 9305afac5fa..df4be9b9fd3 100644 --- a/core/io/ip_address.cpp +++ b/core/io/ip_address.cpp @@ -81,8 +81,7 @@ static void _parse_hex(const String &p_string, int p_start, uint8_t *p_dst) { } else if (c == ':') { break; } else { - ERR_EXPLAIN("Invalid character in ipv6 address: " + p_string); - ERR_FAIL(); + ERR_FAIL_MSG("Invalid character in IPv6 address: " + p_string + "."); }; ret = ret << 4; ret += n; @@ -126,9 +125,7 @@ void IP_Address::_parse_ipv6(const String &p_string) { ++parts_count; }; } else { - - ERR_EXPLAIN("Invalid character in IPv6 address: " + p_string); - ERR_FAIL(); + ERR_FAIL_MSG("Invalid character in IPv6 address: " + p_string + "."); }; }; @@ -166,10 +163,7 @@ void IP_Address::_parse_ipv4(const String &p_string, int p_start, uint8_t *p_ret }; int slices = ip.get_slice_count("."); - if (slices != 4) { - ERR_EXPLAIN("Invalid IP Address String: " + ip); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(slices != 4, "Invalid IP address string: " + ip + "."); for (int i = 0; i < 4; i++) { p_ret[i] = ip.get_slicec('.', i).to_int(); } @@ -229,7 +223,7 @@ IP_Address::IP_Address(const String &p_string) { valid = true; } else { - ERR_PRINT("Invalid IP address"); + ERR_PRINT("Invalid IP address."); } } diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp index dc5581ea019..b386feb14c7 100644 --- a/core/io/marshalls.cpp +++ b/core/io/marshalls.cpp @@ -377,11 +377,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } } break; - /*case Variant::RESOURCE: { - - ERR_EXPLAIN("Can't marshallize resources"); - ERR_FAIL_V(ERR_INVALID_DATA); //no, i'm sorry, no go - } break;*/ case Variant::_RID: { r_variant = RID(); @@ -1066,11 +1061,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo r_len += 4 * 4; } break; - /*case Variant::RESOURCE: { - - ERR_EXPLAIN("Can't marshallize resources"); - ERR_FAIL_V(ERR_INVALID_DATA); //no, i'm sorry, no go - } break;*/ case Variant::_RID: { } break; diff --git a/core/io/multiplayer_api.cpp b/core/io/multiplayer_api.cpp index 33dc4dbde49..d20133642be 100644 --- a/core/io/multiplayer_api.cpp +++ b/core/io/multiplayer_api.cpp @@ -146,8 +146,7 @@ void MultiplayerAPI::set_network_peer(const Ref &p_pee network_peer = p_peer; - ERR_EXPLAIN("Supplied NetworkedNetworkPeer must be connecting or connected."); - ERR_FAIL_COND(p_peer.is_valid() && p_peer->get_connection_status() == NetworkedMultiplayerPeer::CONNECTION_DISCONNECTED); + ERR_FAIL_COND_MSG(p_peer.is_valid() && p_peer->get_connection_status() == NetworkedMultiplayerPeer::CONNECTION_DISCONNECTED, "Supplied NetworkedNetworkPeer must be connecting or connected."); if (network_peer.is_valid()) { network_peer->connect("peer_connected", this, "_add_peer"); @@ -164,10 +163,8 @@ Ref MultiplayerAPI::get_network_peer() const { void MultiplayerAPI::_process_packet(int p_from, const uint8_t *p_packet, int p_packet_len) { - ERR_EXPLAIN("Multiplayer root node was not initialized. If you are using custom multiplayer, remember to set the root node via MultiplayerAPI.set_root_node before using it"); - ERR_FAIL_COND(root_node == NULL); - ERR_EXPLAIN("Invalid packet received. Size too small."); - ERR_FAIL_COND(p_packet_len < 1); + ERR_FAIL_COND_MSG(root_node == NULL, "Multiplayer root node was not initialized. If you are using custom multiplayer, remember to set the root node via MultiplayerAPI.set_root_node before using it."); + ERR_FAIL_COND_MSG(p_packet_len < 1, "Invalid packet received. Size too small."); uint8_t packet_type = p_packet[0]; @@ -186,13 +183,11 @@ void MultiplayerAPI::_process_packet(int p_from, const uint8_t *p_packet, int p_ case NETWORK_COMMAND_REMOTE_CALL: case NETWORK_COMMAND_REMOTE_SET: { - ERR_EXPLAIN("Invalid packet received. Size too small."); - ERR_FAIL_COND(p_packet_len < 6); + ERR_FAIL_COND_MSG(p_packet_len < 6, "Invalid packet received. Size too small."); Node *node = _process_get_node(p_from, p_packet, p_packet_len); - ERR_EXPLAIN("Invalid packet received. Requested node was not found."); - ERR_FAIL_COND(node == NULL); + ERR_FAIL_COND_MSG(node == NULL, "Invalid packet received. Requested node was not found."); // Detect cstring end. int len_end = 5; @@ -202,8 +197,7 @@ void MultiplayerAPI::_process_packet(int p_from, const uint8_t *p_packet, int p_ } } - ERR_EXPLAIN("Invalid packet received. Size too small."); - ERR_FAIL_COND(len_end >= p_packet_len); + ERR_FAIL_COND_MSG(len_end >= p_packet_len, "Invalid packet received. Size too small."); StringName name = String::utf8((const char *)&p_packet[5]); @@ -235,8 +229,7 @@ Node *MultiplayerAPI::_process_get_node(int p_from, const uint8_t *p_packet, int int ofs = target & 0x7FFFFFFF; - ERR_EXPLAIN("Invalid packet received. Size smaller than declared."); - ERR_FAIL_COND_V(ofs >= p_packet_len, NULL); + ERR_FAIL_COND_V_MSG(ofs >= p_packet_len, NULL, "Invalid packet received. Size smaller than declared."); String paths; paths.parse_utf8((const char *)&p_packet[ofs], p_packet_len - ofs); @@ -246,33 +239,30 @@ Node *MultiplayerAPI::_process_get_node(int p_from, const uint8_t *p_packet, int node = root_node->get_node(np); if (!node) - ERR_PRINTS("Failed to get path from RPC: " + String(np)); + ERR_PRINTS("Failed to get path from RPC: " + String(np) + "."); } else { // Use cached path. int id = target; Map::Element *E = path_get_cache.find(p_from); - ERR_EXPLAIN("Invalid packet received. Requests invalid peer cache."); - ERR_FAIL_COND_V(!E, NULL); + ERR_FAIL_COND_V_MSG(!E, NULL, "Invalid packet received. Requests invalid peer cache."); Map::Element *F = E->get().nodes.find(id); - ERR_EXPLAIN("Invalid packet received. Unabled to find requested cached node."); - ERR_FAIL_COND_V(!F, NULL); + ERR_FAIL_COND_V_MSG(!F, NULL, "Invalid packet received. Unabled to find requested cached node."); PathGetCache::NodeInfo *ni = &F->get(); // Do proper caching later. node = root_node->get_node(ni->path); if (!node) - ERR_PRINTS("Failed to get cached path from RPC: " + String(ni->path)); + ERR_PRINTS("Failed to get cached path from RPC: " + String(ni->path) + "."); } return node; } void MultiplayerAPI::_process_rpc(Node *p_node, const StringName &p_name, int p_from, const uint8_t *p_packet, int p_packet_len, int p_offset) { - ERR_EXPLAIN("Invalid packet received. Size too small."); - ERR_FAIL_COND(p_offset >= p_packet_len); + ERR_FAIL_COND_MSG(p_offset >= p_packet_len, "Invalid packet received. Size too small."); // Check that remote can call the RPC on this node. RPCMode rpc_mode = RPC_MODE_DISABLED; @@ -284,8 +274,7 @@ void MultiplayerAPI::_process_rpc(Node *p_node, const StringName &p_name, int p_ } bool can_call = _can_call_mode(p_node, rpc_mode, p_from); - ERR_EXPLAIN("RPC '" + String(p_name) + "' is not allowed on node " + p_node->get_path() + " from: " + itos(p_from) + ". Mode is " + itos((int)rpc_mode) + ", master is " + itos(p_node->get_network_master()) + "."); - ERR_FAIL_COND(!can_call); + ERR_FAIL_COND_MSG(!can_call, "RPC '" + String(p_name) + "' is not allowed on node " + p_node->get_path() + " from: " + itos(p_from) + ". Mode is " + itos((int)rpc_mode) + ", master is " + itos(p_node->get_network_master()) + "."); int argc = p_packet[p_offset]; Vector args; @@ -297,13 +286,11 @@ void MultiplayerAPI::_process_rpc(Node *p_node, const StringName &p_name, int p_ for (int i = 0; i < argc; i++) { - ERR_EXPLAIN("Invalid packet received. Size too small."); - ERR_FAIL_COND(p_offset >= p_packet_len); + ERR_FAIL_COND_MSG(p_offset >= p_packet_len, "Invalid packet received. Size too small."); int vlen; Error err = decode_variant(args.write[i], &p_packet[p_offset], p_packet_len - p_offset, &vlen, allow_object_decoding || network_peer->is_object_decoding_allowed()); - ERR_EXPLAIN("Invalid packet received. Unable to decode RPC argument."); - ERR_FAIL_COND(err != OK); + ERR_FAIL_COND_MSG(err != OK, "Invalid packet received. Unable to decode RPC argument."); argp.write[i] = &args[i]; p_offset += vlen; @@ -321,8 +308,7 @@ void MultiplayerAPI::_process_rpc(Node *p_node, const StringName &p_name, int p_ void MultiplayerAPI::_process_rset(Node *p_node, const StringName &p_name, int p_from, const uint8_t *p_packet, int p_packet_len, int p_offset) { - ERR_EXPLAIN("Invalid packet received. Size too small."); - ERR_FAIL_COND(p_offset >= p_packet_len); + ERR_FAIL_COND_MSG(p_offset >= p_packet_len, "Invalid packet received. Size too small."); // Check that remote can call the RSET on this node. RPCMode rset_mode = RPC_MODE_DISABLED; @@ -334,28 +320,25 @@ void MultiplayerAPI::_process_rset(Node *p_node, const StringName &p_name, int p } bool can_call = _can_call_mode(p_node, rset_mode, p_from); - ERR_EXPLAIN("RSET '" + String(p_name) + "' is not allowed on node " + p_node->get_path() + " from: " + itos(p_from) + ". Mode is " + itos((int)rset_mode) + ", master is " + itos(p_node->get_network_master()) + "."); - ERR_FAIL_COND(!can_call); + ERR_FAIL_COND_MSG(!can_call, "RSET '" + String(p_name) + "' is not allowed on node " + p_node->get_path() + " from: " + itos(p_from) + ". Mode is " + itos((int)rset_mode) + ", master is " + itos(p_node->get_network_master()) + "."); Variant value; Error err = decode_variant(value, &p_packet[p_offset], p_packet_len - p_offset, NULL, allow_object_decoding || network_peer->is_object_decoding_allowed()); - ERR_EXPLAIN("Invalid packet received. Unable to decode RSET value."); - ERR_FAIL_COND(err != OK); + ERR_FAIL_COND_MSG(err != OK, "Invalid packet received. Unable to decode RSET value."); bool valid; p_node->set(p_name, value, &valid); if (!valid) { - String error = "Error setting remote property '" + String(p_name) + "', not found in object of type " + p_node->get_class(); + String error = "Error setting remote property '" + String(p_name) + "', not found in object of type " + p_node->get_class() + "."; ERR_PRINTS(error); } } void MultiplayerAPI::_process_simplify_path(int p_from, const uint8_t *p_packet, int p_packet_len) { - ERR_EXPLAIN("Invalid packet received. Size too small."); - ERR_FAIL_COND(p_packet_len < 5); + ERR_FAIL_COND_MSG(p_packet_len < 5, "Invalid packet received. Size too small."); int id = decode_uint32(&p_packet[1]); String paths; @@ -390,8 +373,7 @@ void MultiplayerAPI::_process_simplify_path(int p_from, const uint8_t *p_packet, void MultiplayerAPI::_process_confirm_path(int p_from, const uint8_t *p_packet, int p_packet_len) { - ERR_EXPLAIN("Invalid packet received. Size too small."); - ERR_FAIL_COND(p_packet_len < 2); + ERR_FAIL_COND_MSG(p_packet_len < 2, "Invalid packet received. Size too small."); String paths; paths.parse_utf8((const char *)&p_packet[1], p_packet_len - 1); @@ -399,12 +381,10 @@ void MultiplayerAPI::_process_confirm_path(int p_from, const uint8_t *p_packet, NodePath path = paths; PathSentCache *psc = path_send_cache.getptr(path); - ERR_EXPLAIN("Invalid packet received. Tries to confirm a path which was not found in cache."); - ERR_FAIL_COND(!psc); + ERR_FAIL_COND_MSG(!psc, "Invalid packet received. Tries to confirm a path which was not found in cache."); Map::Element *E = psc->confirmed_peers.find(p_from); - ERR_EXPLAIN("Invalid packet received. Source peer was not found in cache for the given path."); - ERR_FAIL_COND(!E); + ERR_FAIL_COND_MSG(!E, "Invalid packet received. Source peer was not found in cache for the given path."); E->get() = true; } @@ -460,39 +440,22 @@ bool MultiplayerAPI::_send_confirm_path(NodePath p_path, PathSentCache *psc, int void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p_set, const StringName &p_name, const Variant **p_arg, int p_argcount) { - if (network_peer.is_null()) { - ERR_EXPLAIN("Attempt to remote call/set when networking is not active in SceneTree."); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(network_peer.is_null(), "Attempt to remote call/set when networking is not active in SceneTree."); - if (network_peer->get_connection_status() == NetworkedMultiplayerPeer::CONNECTION_CONNECTING) { - ERR_EXPLAIN("Attempt to remote call/set when networking is not connected yet in SceneTree."); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(network_peer->get_connection_status() == NetworkedMultiplayerPeer::CONNECTION_CONNECTING, "Attempt to remote call/set when networking is not connected yet in SceneTree."); - if (network_peer->get_connection_status() == NetworkedMultiplayerPeer::CONNECTION_DISCONNECTED) { - ERR_EXPLAIN("Attempt to remote call/set when networking is disconnected."); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(network_peer->get_connection_status() == NetworkedMultiplayerPeer::CONNECTION_DISCONNECTED, "Attempt to remote call/set when networking is disconnected."); - if (p_argcount > 255) { - ERR_EXPLAIN("Too many arguments >255."); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(p_argcount > 255, "Too many arguments >255."); if (p_to != 0 && !connected_peers.has(ABS(p_to))) { - if (p_to == network_peer->get_unique_id()) { - ERR_EXPLAIN("Attempt to remote call/set yourself! unique ID: " + itos(network_peer->get_unique_id())); - } else { - ERR_EXPLAIN("Attempt to remote call unexisting ID: " + itos(p_to)); - } + ERR_FAIL_COND_MSG(p_to == network_peer->get_unique_id(), "Attempt to remote call/set yourself! unique ID: " + itos(network_peer->get_unique_id()) + "."); - ERR_FAIL(); + ERR_FAIL_MSG("Attempt to remote call unexisting ID: " + itos(p_to) + "."); } NodePath from_path = (root_node->get_path()).rel_path_to(p_from->get_path()); - ERR_EXPLAIN("Unable to send RPC. Relative path is empty. THIS IS LIKELY A BUG IN THE ENGINE!"); - ERR_FAIL_COND(from_path.is_empty()); + ERR_FAIL_COND_MSG(from_path.is_empty(), "Unable to send RPC. Relative path is empty. THIS IS LIKELY A BUG IN THE ENGINE!"); // See if the path is cached. PathSentCache *psc = path_send_cache.getptr(from_path); @@ -530,8 +493,7 @@ void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p if (p_set) { // Set argument. Error err = encode_variant(*p_arg[0], NULL, len, allow_object_decoding || network_peer->is_object_decoding_allowed()); - ERR_EXPLAIN("Unable to encode RSET value. THIS IS LIKELY A BUG IN THE ENGINE!"); - ERR_FAIL_COND(err != OK); + ERR_FAIL_COND_MSG(err != OK, "Unable to encode RSET value. THIS IS LIKELY A BUG IN THE ENGINE!"); MAKE_ROOM(ofs + len); encode_variant(*p_arg[0], &(packet_cache.write[ofs]), len, allow_object_decoding || network_peer->is_object_decoding_allowed()); ofs += len; @@ -543,8 +505,7 @@ void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p ofs += 1; for (int i = 0; i < p_argcount; i++) { Error err = encode_variant(*p_arg[i], NULL, len, allow_object_decoding || network_peer->is_object_decoding_allowed()); - ERR_EXPLAIN("Unable to encode RPC argument. THIS IS LIKELY A BUG IN THE ENGINE!"); - ERR_FAIL_COND(err != OK); + ERR_FAIL_COND_MSG(err != OK, "Unable to encode RPC argument. THIS IS LIKELY A BUG IN THE ENGINE!"); MAKE_ROOM(ofs + len); encode_variant(*p_arg[i], &(packet_cache.write[ofs]), len, allow_object_decoding || network_peer->is_object_decoding_allowed()); ofs += len; @@ -626,12 +587,9 @@ void MultiplayerAPI::_server_disconnected() { void MultiplayerAPI::rpcp(Node *p_node, int p_peer_id, bool p_unreliable, const StringName &p_method, const Variant **p_arg, int p_argcount) { - ERR_EXPLAIN("Trying to call an RPC while no network peer is active."); - ERR_FAIL_COND(!network_peer.is_valid()); - ERR_EXPLAIN("Trying to call an RPC on a node which is not inside SceneTree."); - ERR_FAIL_COND(!p_node->is_inside_tree()); - ERR_EXPLAIN("Trying to call an RPC via a network peer which is not connected."); - ERR_FAIL_COND(network_peer->get_connection_status() != NetworkedMultiplayerPeer::CONNECTION_CONNECTED); + ERR_FAIL_COND_MSG(!network_peer.is_valid(), "Trying to call an RPC while no network peer is active."); + ERR_FAIL_COND_MSG(!p_node->is_inside_tree(), "Trying to call an RPC on a node which is not inside SceneTree."); + ERR_FAIL_COND_MSG(network_peer->get_connection_status() != NetworkedMultiplayerPeer::CONNECTION_CONNECTED, "Trying to call an RPC via a network peer which is not connected."); int node_id = network_peer->get_unique_id(); bool skip_rpc = node_id == p_peer_id; @@ -668,7 +626,7 @@ void MultiplayerAPI::rpcp(Node *p_node, int p_peer_id, bool p_unreliable, const rpc_sender_id = temp_id; if (ce.error != Variant::CallError::CALL_OK) { String error = Variant::get_call_error_text(p_node, p_method, p_arg, p_argcount, ce); - error = "rpc() aborted in local call: - " + error; + error = "rpc() aborted in local call: - " + error + "."; ERR_PRINTS(error); return; } @@ -683,24 +641,20 @@ void MultiplayerAPI::rpcp(Node *p_node, int p_peer_id, bool p_unreliable, const rpc_sender_id = temp_id; if (ce.error != Variant::CallError::CALL_OK) { String error = Variant::get_call_error_text(p_node, p_method, p_arg, p_argcount, ce); - error = "rpc() aborted in script local call: - " + error; + error = "rpc() aborted in script local call: - " + error + "."; ERR_PRINTS(error); return; } } - ERR_EXPLAIN("RPC '" + p_method + "' on yourself is not allowed by selected mode"); - ERR_FAIL_COND(skip_rpc && !(call_local_native || call_local_script)); + ERR_FAIL_COND_MSG(skip_rpc && !(call_local_native || call_local_script), "RPC '" + p_method + "' on yourself is not allowed by selected mode."); } void MultiplayerAPI::rsetp(Node *p_node, int p_peer_id, bool p_unreliable, const StringName &p_property, const Variant &p_value) { - ERR_EXPLAIN("Trying to RSET while no network peer is active."); - ERR_FAIL_COND(!network_peer.is_valid()); - ERR_EXPLAIN("Trying to RSET on a node which is not inside SceneTree."); - ERR_FAIL_COND(!p_node->is_inside_tree()); - ERR_EXPLAIN("Trying to send an RSET via a network peer which is not connected."); - ERR_FAIL_COND(network_peer->get_connection_status() != NetworkedMultiplayerPeer::CONNECTION_CONNECTED); + ERR_FAIL_COND_MSG(!network_peer.is_valid(), "Trying to RSET while no network peer is active."); + ERR_FAIL_COND_MSG(!p_node->is_inside_tree(), "Trying to RSET on a node which is not inside SceneTree."); + ERR_FAIL_COND_MSG(network_peer->get_connection_status() != NetworkedMultiplayerPeer::CONNECTION_CONNECTED, "Trying to send an RSET via a network peer which is not connected."); int node_id = network_peer->get_unique_id(); bool is_master = p_node->is_network_master(); @@ -724,7 +678,7 @@ void MultiplayerAPI::rsetp(Node *p_node, int p_peer_id, bool p_unreliable, const rpc_sender_id = temp_id; if (!valid) { - String error = "rset() aborted in local set, property not found: - " + String(p_property); + String error = "rset() aborted in local set, property not found: - " + String(p_property) + "."; ERR_PRINTS(error); return; } @@ -742,7 +696,7 @@ void MultiplayerAPI::rsetp(Node *p_node, int p_peer_id, bool p_unreliable, const rpc_sender_id = temp_id; if (!valid) { - String error = "rset() aborted in local script set, property not found: - " + String(p_property); + String error = "rset() aborted in local script set, property not found: - " + String(p_property) + "."; ERR_PRINTS(error); return; } @@ -751,8 +705,7 @@ void MultiplayerAPI::rsetp(Node *p_node, int p_peer_id, bool p_unreliable, const } if (skip_rset) { - ERR_EXPLAIN("RSET for '" + p_property + "' on yourself is not allowed by selected mode"); - ERR_FAIL_COND(!set_local); + ERR_FAIL_COND_MSG(!set_local, "RSET for '" + p_property + "' on yourself is not allowed by selected mode."); return; } @@ -763,12 +716,9 @@ void MultiplayerAPI::rsetp(Node *p_node, int p_peer_id, bool p_unreliable, const Error MultiplayerAPI::send_bytes(PoolVector p_data, int p_to, NetworkedMultiplayerPeer::TransferMode p_mode) { - ERR_EXPLAIN("Trying to send an empty raw packet."); - ERR_FAIL_COND_V(p_data.size() < 1, ERR_INVALID_DATA); - ERR_EXPLAIN("Trying to send a raw packet while no network peer is active."); - ERR_FAIL_COND_V(!network_peer.is_valid(), ERR_UNCONFIGURED); - ERR_EXPLAIN("Trying to send a raw packet via a network peer which is not connected."); - ERR_FAIL_COND_V(network_peer->get_connection_status() != NetworkedMultiplayerPeer::CONNECTION_CONNECTED, ERR_UNCONFIGURED); + ERR_FAIL_COND_V_MSG(p_data.size() < 1, ERR_INVALID_DATA, "Trying to send an empty raw packet."); + ERR_FAIL_COND_V_MSG(!network_peer.is_valid(), ERR_UNCONFIGURED, "Trying to send a raw packet while no network peer is active."); + ERR_FAIL_COND_V_MSG(network_peer->get_connection_status() != NetworkedMultiplayerPeer::CONNECTION_CONNECTED, ERR_UNCONFIGURED, "Trying to send a raw packet via a network peer which is not connected."); MAKE_ROOM(p_data.size() + 1); PoolVector::Read r = p_data.read(); @@ -783,8 +733,7 @@ Error MultiplayerAPI::send_bytes(PoolVector p_data, int p_to, Networked void MultiplayerAPI::_process_raw(int p_from, const uint8_t *p_packet, int p_packet_len) { - ERR_EXPLAIN("Invalid packet received. Size too small."); - ERR_FAIL_COND(p_packet_len < 2); + ERR_FAIL_COND_MSG(p_packet_len < 2, "Invalid packet received. Size too small."); PoolVector out; int len = p_packet_len - 1; @@ -798,37 +747,32 @@ void MultiplayerAPI::_process_raw(int p_from, const uint8_t *p_packet, int p_pac int MultiplayerAPI::get_network_unique_id() const { - ERR_EXPLAIN("No network peer is assigned. Unable to get unique network ID."); - ERR_FAIL_COND_V(!network_peer.is_valid(), 0); + ERR_FAIL_COND_V_MSG(!network_peer.is_valid(), 0, "No network peer is assigned. Unable to get unique network ID."); return network_peer->get_unique_id(); } bool MultiplayerAPI::is_network_server() const { // XXX Maybe fail silently? Maybe should actually return true to make development of both local and online multiplayer easier? - ERR_EXPLAIN("No network peer is assigned. I can't be a server."); - ERR_FAIL_COND_V(!network_peer.is_valid(), false); + ERR_FAIL_COND_V_MSG(!network_peer.is_valid(), false, "No network peer is assigned. I can't be a server."); return network_peer->is_server(); } void MultiplayerAPI::set_refuse_new_network_connections(bool p_refuse) { - ERR_EXPLAIN("No network peer is assigned. Unable to set 'refuse_new_connections'."); - ERR_FAIL_COND(!network_peer.is_valid()); + ERR_FAIL_COND_MSG(!network_peer.is_valid(), "No network peer is assigned. Unable to set 'refuse_new_connections'."); network_peer->set_refuse_new_connections(p_refuse); } bool MultiplayerAPI::is_refusing_new_network_connections() const { - ERR_EXPLAIN("No network peer is assigned. Unable to get 'refuse_new_connections'."); - ERR_FAIL_COND_V(!network_peer.is_valid(), false); + ERR_FAIL_COND_V_MSG(!network_peer.is_valid(), false, "No network peer is assigned. Unable to get 'refuse_new_connections'."); return network_peer->is_refusing_new_connections(); } Vector MultiplayerAPI::get_network_connected_peers() const { - ERR_EXPLAIN("No network peer is assigned. Assume no peers are connected."); - ERR_FAIL_COND_V(!network_peer.is_valid(), Vector()); + ERR_FAIL_COND_V_MSG(!network_peer.is_valid(), Vector(), "No network peer is assigned. Assume no peers are connected."); Vector ret; for (Set::Element *E = connected_peers.front(); E; E = E->next()) { diff --git a/core/io/packet_peer.cpp b/core/io/packet_peer.cpp index 1e4ea715b3f..1c792c43d10 100644 --- a/core/io/packet_peer.cpp +++ b/core/io/packet_peer.cpp @@ -280,8 +280,7 @@ Ref PacketPeerStream::get_stream_peer() const { void PacketPeerStream::set_input_buffer_max_size(int p_max_size) { //warning may lose packets - ERR_EXPLAIN("Buffer in use, resizing would cause loss of data"); - ERR_FAIL_COND(ring_buffer.data_left()); + ERR_FAIL_COND_MSG(ring_buffer.data_left(), "Buffer in use, resizing would cause loss of data."); ring_buffer.resize(nearest_shift(p_max_size + 4)); input_buffer.resize(next_power_of_2(p_max_size + 4)); } diff --git a/core/io/pck_packer.cpp b/core/io/pck_packer.cpp index c16d89d695c..1c89bc6268d 100644 --- a/core/io/pck_packer.cpp +++ b/core/io/pck_packer.cpp @@ -64,10 +64,7 @@ Error PCKPacker::pck_start(const String &p_file, int p_alignment) { file = FileAccess::open(p_file, FileAccess::WRITE); - if (!file) { - ERR_EXPLAIN("Can't open file to write: " + String(p_file)); - ERR_FAIL_V(ERR_CANT_CREATE); - } + ERR_FAIL_COND_V_MSG(!file, ERR_CANT_CREATE, "Can't open file to write: " + String(p_file) + "."); alignment = p_alignment; diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index 146480e5a26..de10fe1376a 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -490,8 +490,7 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { #endif } else { - ERR_EXPLAIN("Vector2 size is NOT 8!"); - ERR_FAIL_V(ERR_UNAVAILABLE); + ERR_FAIL_V_MSG(ERR_UNAVAILABLE, "Vector2 size is NOT 8!"); } w.release(); r_v = array; @@ -518,8 +517,7 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { #endif } else { - ERR_EXPLAIN("Vector3 size is NOT 12!"); - ERR_FAIL_V(ERR_UNAVAILABLE); + ERR_FAIL_V_MSG(ERR_UNAVAILABLE, "Vector3 size is NOT 12!"); } w.release(); r_v = array; @@ -546,8 +544,7 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { #endif } else { - ERR_EXPLAIN("Color size is NOT 16!"); - ERR_FAIL_V(ERR_UNAVAILABLE); + ERR_FAIL_V_MSG(ERR_UNAVAILABLE, "Color size is NOT 16!"); } w.release(); r_v = array; @@ -571,7 +568,7 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { const uint32_t current_version = 0; if (format_version > current_version) { - ERR_PRINT("Format version for encoded binary image is too new"); + ERR_PRINT("Format version for encoded binary image is too new."); return ERR_PARSE_ERROR; } @@ -655,8 +652,7 @@ Error ResourceInteractiveLoaderBinary::poll() { } else { error = ERR_FILE_MISSING_DEPENDENCIES; - ERR_EXPLAIN("Can't load dependency: " + path); - ERR_FAIL_V(error); + ERR_FAIL_V_MSG(error, "Can't load dependency: " + path + "."); } } else { @@ -711,16 +707,15 @@ Error ResourceInteractiveLoaderBinary::poll() { Object *obj = ClassDB::instance(t); if (!obj) { error = ERR_FILE_CORRUPT; - ERR_EXPLAIN(local_path + ":Resource of unrecognized type in file: " + t); - ERR_FAIL_V(ERR_FILE_CORRUPT); + ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, local_path + ":Resource of unrecognized type in file: " + t + "."); } Resource *r = Object::cast_to(obj); if (!r) { + String obj_class = obj->get_class(); error = ERR_FILE_CORRUPT; - ERR_EXPLAIN(local_path + ":Resource type in resource field not a resource, type is: " + obj->get_class()); memdelete(obj); //bye - ERR_FAIL_V(ERR_FILE_CORRUPT); + ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, local_path + ":Resource type in resource field not a resource, type is: " + obj_class + "."); } RES res = RES(r); @@ -850,8 +845,7 @@ void ResourceInteractiveLoaderBinary::open(FileAccess *p_f) { //not normal error = ERR_FILE_UNRECOGNIZED; - ERR_EXPLAIN("Unrecognized binary resource file: " + local_path); - ERR_FAIL(); + ERR_FAIL_MSG("Unrecognized binary resource file: " + local_path + "."); } bool big_endian = f->get_32(); @@ -877,8 +871,7 @@ void ResourceInteractiveLoaderBinary::open(FileAccess *p_f) { if (ver_format > FORMAT_VERSION || ver_major > VERSION_MAJOR) { f->close(); - ERR_EXPLAIN("File Format '" + itos(FORMAT_VERSION) + "." + itos(ver_major) + "." + itos(ver_minor) + "' is too new! Please upgrade to a new engine version: " + local_path); - ERR_FAIL(); + ERR_FAIL_MSG("File format '" + itos(FORMAT_VERSION) + "." + itos(ver_major) + "." + itos(ver_minor) + "' is too new! Please upgrade to a new engine version: " + local_path + "."); } type = get_unicode_string(); @@ -926,8 +919,7 @@ void ResourceInteractiveLoaderBinary::open(FileAccess *p_f) { if (f->eof_reached()) { error = ERR_FILE_CORRUPT; - ERR_EXPLAIN("Premature End Of File: " + local_path); - ERR_FAIL(); + ERR_FAIL_MSG("Premature end of file (EOF): " + local_path + "."); } } @@ -1084,8 +1076,7 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons //error=ERR_FILE_UNRECOGNIZED; memdelete(f); - ERR_EXPLAIN("Unrecognized binary resource file: " + local_path); - ERR_FAIL_V(ERR_FILE_UNRECOGNIZED); + ERR_FAIL_V_MSG(ERR_FILE_UNRECOGNIZED, "Unrecognized binary resource file: " + local_path + "."); } else { fw = FileAccess::open(p_path + ".depren", FileAccess::WRITE); if (!fw) { @@ -1122,7 +1113,7 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons memdelete(da); //use the old approach - WARN_PRINT(("This file is old, so it can't refactor dependencies, opening and resaving: " + p_path).utf8().get_data()); + 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); @@ -1153,8 +1144,7 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons memdelete(f); memdelete(fw); - ERR_EXPLAIN("File Format '" + itos(FORMAT_VERSION) + "." + itos(ver_major) + "." + itos(ver_minor) + "' is too new! Please upgrade to a new engine version: " + local_path); - ERR_FAIL_V(ERR_FILE_UNRECOGNIZED); + ERR_FAIL_V_MSG(ERR_FILE_UNRECOGNIZED, "File format '" + itos(FORMAT_VERSION) + "." + itos(ver_major) + "." + itos(ver_minor) + "' is too new! Please upgrade to a new engine version: " + local_path + "."); } // Since we're not actually converting the file contents, leave the version @@ -1477,7 +1467,7 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia case Variant::_RID: { f->store_32(VARIANT_RID); - WARN_PRINT("Can't save RIDs"); + WARN_PRINT("Can't save RIDs."); RID val = p_property; f->store_32(val.get_id()); } break; @@ -1497,8 +1487,7 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia if (!resource_set.has(res)) { f->store_32(OBJECT_EMPTY); - ERR_EXPLAIN("Resource was not pre cached for the resource section, most likely due to circular refedence."); - ERR_FAIL(); + ERR_FAIL_MSG("Resource was not pre cached for the resource section, most likely due to circular reference."); } f->store_32(OBJECT_INTERNAL_RESOURCE); @@ -1629,8 +1618,7 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; default: { - ERR_EXPLAIN("Invalid variant"); - ERR_FAIL(); + ERR_FAIL_MSG("Invalid variant."); } } } diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index 35af58ad071..9e954890bc5 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -275,12 +275,9 @@ RES ResourceLoader::_load(const String &p_path, const String &p_original_path, c return res; } - if (found) { - ERR_EXPLAIN("Failed loading resource: " + p_path); - } else { - ERR_EXPLAIN("No loader found for resource: " + p_path); - } - ERR_FAIL_V(RES()); + ERR_FAIL_COND_V_MSG(found, RES(), "Failed loading resource: " + p_path + "."); + + ERR_FAIL_V_MSG(RES(), "No loader found for resource: " + p_path + "."); } bool ResourceLoader::_add_to_loading_map(const String &p_path) { @@ -355,10 +352,7 @@ RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p { bool success = _add_to_loading_map(local_path); - if (!success) { - ERR_EXPLAIN("Resource: '" + local_path + "' is already being loaded. Cyclic reference?"); - ERR_FAIL_V(RES()); - } + ERR_FAIL_COND_V_MSG(!success, RES(), "Resource: '" + local_path + "' is already being loaded. Cyclic reference?"); } //lock first if possible @@ -395,8 +389,7 @@ RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p if (!p_no_cache) { _remove_from_loading_map(local_path); } - ERR_EXPLAIN("Remapping '" + local_path + "'failed."); - ERR_FAIL_V(RES()); + ERR_FAIL_V_MSG(RES(), "Remapping '" + local_path + "' failed."); } print_verbose("Loading resource: " + path); @@ -479,10 +472,7 @@ Ref ResourceLoader::load_interactive(const String &p_ if (!p_no_cache) { bool success = _add_to_loading_map(local_path); - if (!success) { - ERR_EXPLAIN("Resource: '" + local_path + "' is already being loaded. Cyclic reference?"); - ERR_FAIL_V(RES()); - } + ERR_FAIL_COND_V_MSG(!success, RES(), "Resource: '" + local_path + "' is already being loaded. Cyclic reference?"); if (ResourceCache::has(local_path)) { @@ -503,8 +493,7 @@ Ref ResourceLoader::load_interactive(const String &p_ if (!p_no_cache) { _remove_from_loading_map(local_path); } - ERR_EXPLAIN("Remapping '" + local_path + "'failed."); - ERR_FAIL_V(RES()); + ERR_FAIL_V_MSG(RES(), "Remapping '" + local_path + "' failed."); } print_verbose("Loading resource: " + path); @@ -534,12 +523,9 @@ Ref ResourceLoader::load_interactive(const String &p_ _remove_from_loading_map(local_path); } - if (found) { - ERR_EXPLAIN("Failed loading resource: " + path); - } else { - ERR_EXPLAIN("No loader found for resource: " + path); - } - ERR_FAIL_V(Ref()); + ERR_FAIL_COND_V_MSG(found, Ref(), "Failed loading resource: " + path + "."); + + ERR_FAIL_V_MSG(Ref(), "No loader found for resource: " + path + "."); } void ResourceLoader::add_resource_format_loader(Ref p_format_loader, bool p_at_front) { @@ -801,7 +787,7 @@ String ResourceLoader::_path_remap(const String &p_path, bool *r_translation_rem if (err == ERR_FILE_EOF) { break; } else if (err != OK) { - ERR_PRINTS("Parse error: " + p_path + ".remap:" + itos(lines) + " error: " + error_text); + ERR_PRINTS("Parse error: " + p_path + ".remap:" + itos(lines) + " error: " + error_text + "."); break; } @@ -932,13 +918,11 @@ bool ResourceLoader::add_custom_resource_format_loader(String script_path) { Ref