Skip to content

Commit

Permalink
Replace last occurrences of 'ERR_EXPLAIN' with 'ERR_FAIL_*_MSG'
Browse files Browse the repository at this point in the history
The last remaining ERR_EXPLAIN call is in FreeType code and makes sense as is
(conditionally defines the error message).

There are a few ERR_EXPLAINC calls for C-strings where String is not included
which can stay as is to avoid adding additional _MSGC macros just for that.

Part of godotengine#31244.
  • Loading branch information
akien-mga committed Aug 17, 2019
1 parent de4aabe commit d3153c2
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 88 deletions.
5 changes: 1 addition & 4 deletions core/io/file_access_buffered_fa.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ class FileAccessBufferedFA : public FileAccessBuffered {

int read_data_block(int p_offset, int p_size, uint8_t *p_dest = 0) const {

if (!f.is_open()) {
ERR_EXPLAIN("Can't read data block, when file is not opened.");
ERR_FAIL_V(-1);
}
ERR_FAIL_COND_V_MSG(!f.is_open(), -1, "Can't read data block when file is not opened.");

((T *)&f)->seek(p_offset);

Expand Down
5 changes: 3 additions & 2 deletions drivers/windows/file_access_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ Error FileAccessWindows::_open(const String &p_path, int p_mode_flags) {
return OK;
}
}

void FileAccessWindows::close() {

if (!f)
Expand Down Expand Up @@ -167,11 +168,11 @@ void FileAccessWindows::close() {
if (close_fail_notify) {
close_fail_notify(save_path);
}

ERR_EXPLAIN("Safe save failed. This may be a permissions problem, but also may happen because you are running a paranoid antivirus. If this is the case, please switch to Windows Defender or disable the 'safe save' option in editor settings. This makes it work, but increases the risk of file corruption in a crash.");
}

save_path = "";

ERR_FAIL_COND_MSG(rename_error, "Safe save failed. This may be a permissions problem, but also may happen because you are running a paranoid antivirus. If this is the case, please switch to Windows Defender or disable the 'safe save' option in editor settings. This makes it work, but increases the risk of file corruption in a crash.");
}
}

Expand Down
21 changes: 5 additions & 16 deletions drivers/xaudio2/audio_driver_xaudio2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,10 @@ Error AudioDriverXAudio2::init() {

HRESULT hr;
hr = XAudio2Create(&xaudio, 0, XAUDIO2_DEFAULT_PROCESSOR);
if (hr != S_OK) {
ERR_EXPLAIN("Error creating XAudio2 engine.");
ERR_FAIL_V(ERR_UNAVAILABLE);
}
ERR_FAIL_COND_V_MSG(hr != S_OK, ERR_UNAVAILABLE, "Error creating XAudio2 engine.");

hr = xaudio->CreateMasteringVoice(&mastering_voice);
if (hr != S_OK) {
ERR_EXPLAIN("Error creating XAudio2 mastering voice.");
ERR_FAIL_V(ERR_UNAVAILABLE);
}
ERR_FAIL_COND_V_MSG(hr != S_OK, ERR_UNAVAILABLE, "Error creating XAudio2 mastering voice.");

wave_format.nChannels = channels;
wave_format.cbSize = 0;
Expand All @@ -82,10 +77,7 @@ Error AudioDriverXAudio2::init() {
wave_format.nAvgBytesPerSec = mix_rate * wave_format.nBlockAlign;

hr = xaudio->CreateSourceVoice(&source_voice, &wave_format, 0, XAUDIO2_MAX_FREQ_RATIO, &voice_callback);
if (hr != S_OK) {
ERR_EXPLAIN("Error creating XAudio2 source voice. " + itos(hr));
ERR_FAIL_V(ERR_UNAVAILABLE);
}
ERR_FAIL_COND_V_MSG(hr != S_OK, ERR_UNAVAILABLE, "Error creating XAudio2 source voice. Error code: " + itos(hr) + ".");

mutex = Mutex::create();
thread = Thread::create(AudioDriverXAudio2::thread_func, this);
Expand Down Expand Up @@ -140,10 +132,7 @@ void AudioDriverXAudio2::start() {

active = true;
HRESULT hr = source_voice->Start(0);
if (hr != S_OK) {
ERR_EXPLAIN("XAudio2 start error " + itos(hr));
ERR_FAIL();
}
ERR_FAIL_COND_MSG(hr != S_OK, "Error starting XAudio2 driver. Error code: " + itos(hr) + ".");
}

int AudioDriverXAudio2::get_mix_rate() const {
Expand Down
14 changes: 0 additions & 14 deletions editor/import/editor_import_collada.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -692,16 +692,6 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ArrayMesh> &p_me

pre_weights[w_i] = weights;

/*
for(Set<int>::Element *E=vertex_map[w_i].front();E;E=E->next()) {
int dst = E->get();
ERR_EXPLAIN("invalid vertex index in array");
ERR_FAIL_INDEX_V(dst,vertex_array.size(),ERR_INVALID_DATA);
vertex_array[dst].weights=weights;
}*/

index_ofs += wstride * amount;
}

Expand All @@ -711,7 +701,6 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ArrayMesh> &p_me

Set<Collada::Vertex> vertex_set; //vertex set will be the vertices
List<int> indices_list; //indices will be the indices
//Map<int,Set<int> > vertex_map; //map vertices (for setting skinning/morph)

/**************************/
/* CREATE PRIMITIVE ARRAY */
Expand Down Expand Up @@ -834,9 +823,6 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ArrayMesh> &p_me
vertex_set.insert(vertex);
}

/* if (!vertex_map.has(vertex_index))
vertex_map[vertex_index]=Set<int>();
vertex_map[vertex_index].insert(index); //should be outside..*/
//build triangles if needed
if (j == 0)
prev2[0] = index;
Expand Down
4 changes: 1 addition & 3 deletions modules/etc/texture_loader_pkm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,8 @@ RES ResourceFormatPKM::load(const String &p_path, const String &p_original_path,
f->set_endian_swap(true);

ETC1Header h;
ERR_EXPLAIN("Invalid or Unsupported PKM texture file: " + p_path);
f->get_buffer((uint8_t *)&h.tag, sizeof(h.tag));
if (strncmp(h.tag, "PKM 10", sizeof(h.tag)))
ERR_FAIL_V(RES());
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();
Expand Down
2 changes: 1 addition & 1 deletion modules/gdscript/gdscript_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ static GDScriptCompletionIdentifier _type_from_gdtype(const GDScriptDataType &p_

switch (p_gdtype.kind) {
case GDScriptDataType::UNINITIALIZED: {
ERR_EXPLAIN("Uninitialized completion. Please report a bug.");
ERR_PRINT("Uninitialized completion. Please report a bug.");
} break;
case GDScriptDataType::BUILTIN: {
ci.type.kind = GDScriptParser::DataType::BUILTIN;
Expand Down
2 changes: 1 addition & 1 deletion modules/gdscript/gdscript_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5761,7 +5761,7 @@ GDScriptParser::DataType GDScriptParser::_type_from_gdtype(const GDScriptDataTyp

switch (p_gdtype.kind) {
case GDScriptDataType::UNINITIALIZED: {
ERR_EXPLAIN("Uninitialized datatype. Please report a bug.");
ERR_PRINT("Uninitialized datatype. Please report a bug.");
} break;
case GDScriptDataType::BUILTIN: {
result.kind = DataType::BUILTIN;
Expand Down
9 changes: 3 additions & 6 deletions modules/hdr/image_loader_hdr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,17 @@ Error ImageLoaderHDR::load_image(Ref<Image> p_image, FileAccess *f, bool p_force

String header = f->get_token();

ERR_FAIL_COND_V(header != "#?RADIANCE" && header != "#?RGBE", ERR_FILE_UNRECOGNIZED);
ERR_FAIL_COND_V_MSG(header != "#?RADIANCE" && header != "#?RGBE", ERR_FILE_UNRECOGNIZED, "Unsupported header information in HDR: " + header + ".");

while (true) {
String line = f->get_line();
ERR_FAIL_COND_V(f->eof_reached(), ERR_FILE_UNRECOGNIZED);
if (line == "") // empty line indicates end of header
break;
if (line.begins_with("FORMAT=")) { // leave option to implement other commands
if (line != "FORMAT=32-bit_rle_rgbe") {
ERR_EXPLAIN("Only 32-bit_rle_rgbe is supported for HDR files.");
return ERR_FILE_UNRECOGNIZED;
}
ERR_FAIL_COND_V_MSG(line != "FORMAT=32-bit_rle_rgbe", ERR_FILE_UNRECOGNIZED, "Only 32-bit_rle_rgbe is supported for HDR files.");
} else if (!line.begins_with("#")) { // not comment
WARN_PRINTS("Ignoring unsupported header information in HDR : " + line);
WARN_PRINTS("Ignoring unsupported header information in HDR: " + line + ".");
}
}

Expand Down
7 changes: 2 additions & 5 deletions modules/webp/image_loader_webp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ static Ref<Image> _webp_lossy_unpack(const PoolVector<uint8_t> &p_buffer) {
errdec = WebPDecodeRGBInto(&r[4], size, dst_w.ptr(), datasize, 3 * features.width) == NULL;
}

//ERR_EXPLAIN("Error decoding webp! - "+p_file);
ERR_FAIL_COND_V(errdec, Ref<Image>());
ERR_FAIL_COND_V_MSG(errdec, Ref<Image>(), "Failed decoding WebP image.");

dst_w.release();

Expand All @@ -121,7 +120,6 @@ Error webp_load_image_from_buffer(Image *p_image, const uint8_t *p_buffer, int p

WebPBitstreamFeatures features;
if (WebPGetFeatures(p_buffer, p_buffer_len, &features) != VP8_STATUS_OK) {
// ERR_EXPLAIN("Error decoding WEBP image");
ERR_FAIL_V(ERR_FILE_CORRUPT);
}

Expand All @@ -138,8 +136,7 @@ Error webp_load_image_from_buffer(Image *p_image, const uint8_t *p_buffer, int p
}
dst_w.release();

//ERR_EXPLAIN("Error decoding webp!");
ERR_FAIL_COND_V(errdec, ERR_FILE_CORRUPT);
ERR_FAIL_COND_V_MSG(errdec, ERR_FILE_CORRUPT, "Failed decoding WebP image.");

p_image->create(features.width, features.height, 0, features.has_alpha ? Image::FORMAT_RGBA8 : Image::FORMAT_RGB8, dst_image);

Expand Down
26 changes: 11 additions & 15 deletions modules/websocket/wsl_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,17 @@ bool WSLClient::_verify_headers(String &r_protocol) {
headers[name] = value;
}

#define _WLS_EXPLAIN(NAME, VALUE) \
ERR_EXPLAIN("Missing or invalid header '" + String(NAME) + "'. Expected value '" + VALUE + "'");
#define _WLS_CHECK(NAME, VALUE) \
_WLS_EXPLAIN(NAME, VALUE); \
ERR_FAIL_COND_V(!headers.has(NAME) || headers[NAME].to_lower() != VALUE, false);
#define _WLS_CHECK_NC(NAME, VALUE) \
_WLS_EXPLAIN(NAME, VALUE); \
ERR_FAIL_COND_V(!headers.has(NAME) || headers[NAME] != VALUE, false);
_WLS_CHECK("connection", "upgrade");
_WLS_CHECK("upgrade", "websocket");
_WLS_CHECK_NC("sec-websocket-accept", WSLPeer::compute_key_response(_key));
#define _WSL_CHECK(NAME, VALUE) \
ERR_FAIL_COND_V_MSG(!headers.has(NAME) || headers[NAME].to_lower() != VALUE, false, \
"Missing or invalid header '" + String(NAME) + "'. Expected value '" + VALUE + "'.");
#define _WSL_CHECK_NC(NAME, VALUE) \
ERR_FAIL_COND_V_MSG(!headers.has(NAME) || headers[NAME] != VALUE, false, \
"Missing or invalid header '" + String(NAME) + "'. Expected value '" + VALUE + "'.");
_WSL_CHECK("connection", "upgrade");
_WSL_CHECK("upgrade", "websocket");
_WSL_CHECK_NC("sec-websocket-accept", WSLPeer::compute_key_response(_key));
#undef _WSL_CHECK_NC
#undef _WSL_CHECK
if (_protocols.size() == 0) {
// We didn't request a custom protocol
ERR_FAIL_COND_V(headers.has("sec-websocket-protocol"), false);
Expand All @@ -148,10 +148,6 @@ bool WSLClient::_verify_headers(String &r_protocol) {
if (!valid)
return false;
}
#undef _WLS_CHECK_NC
#undef _WLS_CHECK
#undef _WLS_EXPLAIN

return true;
}

Expand Down
25 changes: 12 additions & 13 deletions modules/websocket/wsl_server.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*************************************************************************/
/* lws_server.cpp */
/* wsl_server.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
Expand Down Expand Up @@ -64,18 +64,17 @@ bool WSLServer::PendingPeer::_parse_request(const PoolStringArray p_protocols) {
else
headers[name] = value;
}
#define _WLS_CHECK(NAME, VALUE) \
ERR_EXPLAIN("Missing or invalid header '" + String(NAME) + "'. Expected value '" + VALUE + "'"); \
ERR_FAIL_COND_V(!headers.has(NAME) || headers[NAME].to_lower() != VALUE, false);
#define _WLS_CHECK_EX(NAME) \
ERR_EXPLAIN("Missing header '" + String(NAME) + "'."); \
ERR_FAIL_COND_V(!headers.has(NAME), false);
_WLS_CHECK("upgrade", "websocket");
_WLS_CHECK("sec-websocket-version", "13");
_WLS_CHECK_EX("sec-websocket-key");
_WLS_CHECK_EX("connection");
#undef _WLS_CHECK_EX
#undef _WLS_CHECK
#define _WSL_CHECK(NAME, VALUE) \
ERR_FAIL_COND_V_MSG(!headers.has(NAME) || headers[NAME].to_lower() != VALUE, false, \
"Missing or invalid header '" + String(NAME) + "'. Expected value '" + VALUE + "'.");
#define _WSL_CHECK_EX(NAME) \
ERR_FAIL_COND_V_MSG(!headers.has(NAME), false, "Missing header '" + String(NAME) + "'.");
_WSL_CHECK("upgrade", "websocket");
_WSL_CHECK("sec-websocket-version", "13");
_WSL_CHECK_EX("sec-websocket-key");
_WSL_CHECK_EX("connection");
#undef _WSL_CHECK_EX
#undef _WSL_CHECK
key = headers["sec-websocket-key"];
if (headers.has("sec-websocket-protocol")) {
Vector<String> protos = headers["sec-websocket-protocol"].split(",");
Expand Down
3 changes: 3 additions & 0 deletions modules/xatlas_unwrap/register_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@
/*************************************************************************/

#include "register_types.h"

#include "core/error_macros.h"

#include "thirdparty/xatlas/xatlas.h"

#include <stdio.h>
#include <stdlib.h>

extern bool (*array_mesh_lightmap_unwrap_callback)(float p_texel_size, const float *p_vertices, const float *p_normals, int p_vertex_count, const int *p_indices, const int *p_face_materials, int p_index_count, float **r_uv, int **r_vertex, int *r_vertex_count, int **r_index, int *r_index_count, int *r_size_hint_x, int *r_size_hint_y);

bool xatlas_mesh_lightmap_unwrap_callback(float p_texel_size, const float *p_vertices, const float *p_normals, int p_vertex_count, const int *p_indices, const int *p_face_materials, int p_index_count, float **r_uv, int **r_vertex, int *r_vertex_count, int **r_index, int *r_index_count, int *r_size_hint_x, int *r_size_hint_y) {
Expand Down
8 changes: 0 additions & 8 deletions scene/resources/dynamic_font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,6 @@ Error DynamicFontAtSize::_load() {

ERR_FAIL_COND_V(error, ERR_FILE_CANT_OPEN);

/*error = FT_Set_Char_Size(face,0,64*size,512,512);
if ( error ) {
FT_Done_FreeType( library );
ERR_EXPLAIN(TTR("Invalid font size."));
ERR_FAIL_COND_V( error, ERR_INVALID_PARAMETER );
}*/

if (FT_HAS_COLOR(face)) {
int best_match = 0;
int diff = ABS(id.size - ((int64_t)face->available_sizes[0].width));
Expand Down

0 comments on commit d3153c2

Please sign in to comment.