diff options
author | Ignacio Etcheverry <ignalfonsore@gmail.com> | 2019-08-09 03:39:45 +0200 |
---|---|---|
committer | Ignacio Etcheverry <ignalfonsore@gmail.com> | 2019-08-09 12:13:21 +0200 |
commit | c55ce204b3065d55df2717a7e0bcb0681392ac34 (patch) | |
tree | bc672241bc93761fd87db6ba8b1707f9a9f38a3a /modules/mono/csharp_script.cpp | |
parent | fe3cd5175589c27c3564224b317bbc0177a5a735 (diff) |
Replace 'ERR_EXPLAIN' with 'ERR_FAIL_*_MSG' in 'modules/mono'
And 'CRASH_*_MSG' as well.
Also make error messages puntuation and quotation more consistent.
Diffstat (limited to 'modules/mono/csharp_script.cpp')
-rw-r--r-- | modules/mono/csharp_script.cpp | 112 |
1 files changed, 42 insertions, 70 deletions
diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp index f8d201b4ca..8c17bac3c9 100644 --- a/modules/mono/csharp_script.cpp +++ b/modules/mono/csharp_script.cpp @@ -115,7 +115,7 @@ void CSharpLanguage::init() { gdmono->initialize(); #if defined(TOOLS_ENABLED) && defined(DEBUG_METHODS_ENABLED) - // Generate bindings here, before loading assemblies. `initialize_load_assemblies` aborts + // Generate bindings here, before loading assemblies. 'initialize_load_assemblies' aborts // the applications if the api assemblies or the main tools assembly is missing, but this // is not a problem for BindingsGenerator as it only needs the tools project editor assembly. List<String> cmdline_args = OS::get_singleton()->get_cmdline_args(); @@ -123,7 +123,7 @@ void CSharpLanguage::init() { #endif #ifndef MONO_GLUE_ENABLED - print_line("Run this binary with `--generate-mono-glue path/to/modules/mono/glue`"); + print_line("Run this binary with '--generate-mono-glue path/to/modules/mono/glue'"); #endif gdmono->initialize_load_assemblies(); @@ -1036,6 +1036,7 @@ void CSharpLanguage::_load_scripts_metadata() { String old_json; Error ferr = read_all_file_utf8(scripts_metadata_path, old_json); + ERR_FAIL_COND(ferr != OK); Variant old_dict_var; @@ -1043,7 +1044,7 @@ void CSharpLanguage::_load_scripts_metadata() { int err_line; Error json_err = JSON::parse(old_json, old_dict_var, err_str, err_line); if (json_err != OK) { - ERR_PRINTS("Failed to parse metadata file: '" + err_str + "' (" + String::num_int64(err_line) + ")"); + ERR_PRINTS("Failed to parse metadata file: '" + err_str + "' (" + String::num_int64(err_line) + ")."); return; } @@ -1053,7 +1054,7 @@ void CSharpLanguage::_load_scripts_metadata() { print_verbose("Successfully loaded scripts metadata"); } else { if (!Engine::get_singleton()->is_editor_hint()) { - ERR_PRINT("Missing scripts metadata file"); + ERR_PRINT("Missing scripts metadata file."); } } } @@ -1768,12 +1769,8 @@ MonoObject *CSharpInstance::_internal_new_managed() { // Search the constructor first, to fail with an error if it's not found before allocating anything else. GDMonoMethod *ctor = script->script_class->get_method(CACHED_STRING_NAME(dotctor), 0); - if (ctor == NULL) { - ERR_PRINTS("Cannot create script instance because the class does not define a parameterless constructor: " + script->get_path()); - - ERR_EXPLAIN("Constructor not found"); - ERR_FAIL_V(NULL); - } + ERR_FAIL_NULL_V_MSG(ctor, NULL, + "Cannot create script instance because the class does not define a parameterless constructor: '" + script->get_path() + "'."); CSharpLanguage::get_singleton()->release_script_gchandle(gchandle); @@ -1792,8 +1789,7 @@ MonoObject *CSharpInstance::_internal_new_managed() { owner = NULL; - ERR_EXPLAIN("Failed to allocate memory for the object"); - ERR_FAIL_V(NULL); + ERR_FAIL_V_MSG(NULL, "Failed to allocate memory for the object."); } // Tie managed to unmanaged @@ -2233,7 +2229,7 @@ bool CSharpScript::_update_exports() { MonoObject *tmp_object = mono_object_new(mono_domain_get(), script_class->get_mono_ptr()); if (!tmp_object) { - ERR_PRINT("Failed to allocate temporary MonoObject"); + ERR_PRINT("Failed to allocate temporary MonoObject."); return false; } @@ -2241,12 +2237,8 @@ bool CSharpScript::_update_exports() { GDMonoMethod *ctor = script_class->get_method(CACHED_STRING_NAME(dotctor), 0); - if (ctor == NULL) { - ERR_PRINTS("Cannot construct temporary MonoObject because the class does not define a parameterless constructor: " + get_path()); - - ERR_EXPLAIN("Constructor not found"); - ERR_FAIL_V(NULL); - } + ERR_FAIL_NULL_V_MSG(ctor, NULL, + "Cannot construct temporary MonoObject because the class does not define a parameterless constructor: '" + get_path() + "'."); MonoException *ctor_exc = NULL; ctor->invoke(tmp_object, NULL, &ctor_exc); @@ -2399,7 +2391,7 @@ bool CSharpScript::_get_signal(GDMonoClass *p_class, GDMonoClass *p_delegate, Ve arg.type = GDMonoMarshal::managed_to_variant_type(types[i]); if (arg.type == Variant::NIL) { - ERR_PRINTS("Unknown type of signal parameter: " + arg.name + " in " + p_class->get_full_name()); + ERR_PRINTS("Unknown type of signal parameter: '" + arg.name + "' in '" + p_class->get_full_name() + "'."); return false; } @@ -2427,7 +2419,7 @@ bool CSharpScript::_get_member_export(IMonoClassMember *p_member, bool p_inspect if (p_member->is_static()) { if (p_member->has_attribute(CACHED_CLASS(ExportAttribute))) - ERR_PRINTS("Cannot export member because it is static: " + MEMBER_FULL_QUALIFIED_NAME(p_member)); + ERR_PRINTS("Cannot export member because it is static: '" + MEMBER_FULL_QUALIFIED_NAME(p_member) + "'."); return false; } @@ -2450,12 +2442,12 @@ bool CSharpScript::_get_member_export(IMonoClassMember *p_member, bool p_inspect GDMonoProperty *property = static_cast<GDMonoProperty *>(p_member); if (!property->has_getter()) { if (exported) - ERR_PRINTS("Read-only property cannot be exported: " + MEMBER_FULL_QUALIFIED_NAME(p_member)); + ERR_PRINTS("Read-only property cannot be exported: '" + MEMBER_FULL_QUALIFIED_NAME(p_member) + "'."); return false; } if (!property->has_setter()) { if (exported) - ERR_PRINTS("Write-only property (without getter) cannot be exported: " + MEMBER_FULL_QUALIFIED_NAME(p_member)); + ERR_PRINTS("Write-only property (without getter) cannot be exported: '" + MEMBER_FULL_QUALIFIED_NAME(p_member) + "'."); return false; } } @@ -2474,16 +2466,15 @@ bool CSharpScript::_get_member_export(IMonoClassMember *p_member, bool p_inspect String hint_string; if (variant_type == Variant::NIL) { - ERR_PRINTS("Unknown exported member type: " + MEMBER_FULL_QUALIFIED_NAME(p_member)); + ERR_PRINTS("Unknown exported member type: '" + MEMBER_FULL_QUALIFIED_NAME(p_member) + "'."); return false; } int hint_res = _try_get_member_export_hint(p_member, type, variant_type, /* allow_generics: */ true, hint, hint_string); - if (hint_res == -1) { - ERR_EXPLAIN("Error while trying to determine information about the exported member: " + MEMBER_FULL_QUALIFIED_NAME(p_member)); - ERR_FAIL_V(false); - } + ERR_FAIL_COND_V_MSG(hint_res == -1, false, + "Error while trying to determine information about the exported member: '" + + MEMBER_FULL_QUALIFIED_NAME(p_member) + "'."); if (hint_res == 0) { hint = PropertyHint(CACHED_FIELD(ExportAttribute, hint)->get_int_value(attr)); @@ -2532,17 +2523,11 @@ int CSharpScript::_try_get_member_export_hint(IMonoClassMember *p_member, Manage MonoObject *val_obj = mono_field_get_value_object(mono_domain_get(), field, NULL); - if (val_obj == NULL) { - ERR_EXPLAIN("Failed to get '" + enum_field_name + "' constant enum value"); - ERR_FAIL_V(-1); - } + ERR_FAIL_NULL_V_MSG(val_obj, -1, "Failed to get '" + enum_field_name + "' constant enum value."); bool r_error; uint64_t val = GDMonoUtils::unbox_enum_value(val_obj, enum_basetype, r_error); - if (r_error) { - ERR_EXPLAIN("Failed to unbox '" + enum_field_name + "' constant enum value"); - ERR_FAIL_V(-1); - } + ERR_FAIL_COND_V_MSG(r_error, -1, "Failed to unbox '" + enum_field_name + "' constant enum value."); if (val != (unsigned int)i) { uses_default_values = false; @@ -2577,17 +2562,11 @@ int CSharpScript::_try_get_member_export_hint(IMonoClassMember *p_member, Manage PropertyHint elem_hint = PROPERTY_HINT_NONE; String elem_hint_string; - if (elem_variant_type == Variant::NIL) { - ERR_EXPLAIN("Unknown array element type"); - ERR_FAIL_V(-1); - } + ERR_FAIL_COND_V_MSG(elem_variant_type == Variant::NIL, -1, "Unknown array element type."); int hint_res = _try_get_member_export_hint(p_member, elem_type, elem_variant_type, /* allow_generics: */ false, elem_hint, elem_hint_string); - if (hint_res == -1) { - ERR_EXPLAIN("Error while trying to determine information about the array element type"); - ERR_FAIL_V(-1); - } + ERR_FAIL_COND_V_MSG(hint_res == -1, -1, "Error while trying to determine information about the array element type."); // Format: type/hint:hint_string r_hint_string = itos(elem_variant_type) + "/" + itos(elem_hint) + ":" + elem_hint_string; @@ -2775,7 +2754,7 @@ bool CSharpScript::can_instance() const { "Compile", ProjectSettings::get_singleton()->globalize_path(get_path())); } else { - ERR_PRINTS("Cannot add " + get_path() + " to the C# project because it could not be created."); + ERR_PRINTS("C# project could not be created; cannot add file: '" + get_path() + "'."); } } } @@ -2793,12 +2772,10 @@ bool CSharpScript::can_instance() const { if (extra_cond && !script_class) { if (GDMono::get_singleton()->get_project_assembly() == NULL) { // The project assembly is not loaded - ERR_EXPLAIN("Cannot instance script because the project assembly is not loaded. Script: " + get_path()); - ERR_FAIL_V(NULL); + ERR_FAIL_V_MSG(NULL, "Cannot instance script because the project assembly is not loaded. Script: '" + get_path() + "'."); } else { // The project assembly is loaded, but the class could not found - ERR_EXPLAIN("Cannot instance script because the class '" + name + "' could not be found. Script: " + get_path()); - ERR_FAIL_V(NULL); + ERR_FAIL_V_MSG(NULL, "Cannot instance script because the class '" + name + "' could not be found. Script: '" + get_path() + "'."); } } @@ -2820,14 +2797,12 @@ CSharpInstance *CSharpScript::_create_instance(const Variant **p_args, int p_arg // Search the constructor first, to fail with an error if it's not found before allocating anything else. GDMonoMethod *ctor = script_class->get_method(CACHED_STRING_NAME(dotctor), p_argcount); if (ctor == NULL) { - if (p_argcount == 0) { - String path = get_path(); - ERR_PRINTS("Cannot create script instance. The class '" + script_class->get_full_name() + - "' does not define a parameterless constructor." + (path.empty() ? String() : ". Path: " + path)); - } + ERR_FAIL_COND_V_MSG(p_argcount == 0, NULL, + "Cannot create script instance. The class '" + script_class->get_full_name() + + "' does not define a parameterless constructor." + + (get_path().empty() ? String() : " Path: '" + get_path() + "'.")); - ERR_EXPLAIN("Constructor not found"); - ERR_FAIL_V(NULL); + ERR_FAIL_V_MSG(NULL, "Constructor not found."); } Ref<Reference> ref; @@ -2878,8 +2853,7 @@ CSharpInstance *CSharpScript::_create_instance(const Variant **p_args, int p_arg p_owner->set_script_instance(NULL); r_error.error = Variant::CallError::CALL_ERROR_INSTANCE_IS_NULL; - ERR_EXPLAIN("Failed to allocate memory for the object"); - ERR_FAIL_V(NULL); + ERR_FAIL_V_MSG(NULL, "Failed to allocate memory for the object."); } // Tie managed to unmanaged @@ -2950,8 +2924,8 @@ ScriptInstance *CSharpScript::instance_create(Object *p_this) { if (ScriptDebugger::get_singleton()) { CSharpLanguage::get_singleton()->debug_break_parse(get_path(), 0, "Script inherits from native type '" + native_name + "', so it can't be instanced in object of type: '" + p_this->get_class() + "'"); } - ERR_EXPLAIN("Script inherits from native type '" + native_name + "', so it can't be instanced in object of type: '" + p_this->get_class() + "'"); - ERR_FAIL_V(NULL); + ERR_FAIL_V_MSG(NULL, "Script inherits from native type '" + native_name + + "', so it can't be instanced in object of type: '" + p_this->get_class() + "'."); } } @@ -3203,12 +3177,12 @@ int CSharpScript::get_member_line(const StringName &p_member) const { Error CSharpScript::load_source_code(const String &p_path) { Error ferr = read_all_file_utf8(p_path, source); - if (ferr != OK) { - if (ferr == ERR_INVALID_DATA) { - ERR_EXPLAIN("Script '" + p_path + "' contains invalid unicode (utf-8), so it was not loaded. Please ensure that scripts are saved in valid utf-8 unicode."); - } - ERR_FAIL_V(ferr); - } + + ERR_FAIL_COND_V_MSG(ferr != OK, ferr, + ferr == ERR_INVALID_DATA ? + "Script '" + p_path + "' contains invalid unicode (UTF-8), so it was not loaded." + " Please ensure that scripts are saved in valid UTF-8 unicode." : + "Failed to read file: '" + p_path + "'."); #ifdef TOOLS_ENABLED source_changed_cache = true; @@ -3277,8 +3251,7 @@ RES ResourceFormatLoaderCSharpScript::load(const String &p_path, const String &p #ifdef DEBUG_ENABLED // User is responsible for thread attach/detach - ERR_EXPLAIN("Thread is not attached"); - CRASH_COND(mono_domain_get() == NULL); + CRASH_COND_MSG(mono_domain_get() == NULL, "Thread is not attached."); #endif #endif @@ -3345,8 +3318,7 @@ Error ResourceFormatSaverCSharpScript::save(const String &p_path, const RES &p_r "Compile", ProjectSettings::get_singleton()->globalize_path(p_path)); } else { - ERR_PRINTS("Failed to create C# project"); - ERR_PRINTS("Cannot add " + p_path + " to the C# project"); + ERR_PRINTS("C# project could not be created; cannot add file: '" + p_path + "'."); } } #endif |