From 167145e53802a37cfc337afac650495c32f2df72 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Wed, 27 Nov 2024 15:19:33 -0600 Subject: [PATCH] Improve an error message that confused me greatly --- src/scenedit/scen.core.cpp | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/scenedit/scen.core.cpp b/src/scenedit/scen.core.cpp index 63cfe1da..723d6095 100644 --- a/src/scenedit/scen.core.cpp +++ b/src/scenedit/scen.core.cpp @@ -111,7 +111,8 @@ static bool save_ter_info(cDialog& me, cTerrain& ter) { showError("Special type must be either 0 or 1.", &me); return false; } - if(!check_range(me, "flag1", true, 0, (spec_type == 0 ? num_glob : num_loc) - 1, "Special to call")) return false; + if(!check_range_msg(me, "flag1", true, 0, (spec_type == 0 ? num_glob : num_loc) - 1, "Special to call", "ALL towns and outdoor sections must implement this node number")) + return false; break; case eTerSpec::BRIDGE: case eTerSpec::BED: case eTerSpec::IS_A_SIGN: case eTerSpec::IS_A_CONTAINER: case eTerSpec::BLOCKED_TO_MONSTERS: case eTerSpec::WILDERNESS_CAVE: case eTerSpec::WILDERNESS_SURFACE: case eTerSpec::NONE: @@ -169,14 +170,24 @@ bool check_range_msg(cDialog& me,std::string id,bool losing,long min_val,long ma if(!losing) return true; cTextField& fld_ctrl = dynamic_cast(me[id]); long n = fld_ctrl.getTextAsNum(); - if(n < min_val || n > max_val){ - std::ostringstream sout; + std::ostringstream sout; + + if (n >= min_val && n <= max_val){ + return true; + }else if(max_val < min_val){ + // It can be very confusing to be told a number should be from 0 to -1. + // Explain what this really means, and hope that the extra message + // provides context on fixing the problem. + sout << fld_name << " currently has no range of acceptable values"; + if(xtra.empty()){ + xtra = "You can open an issue on GitHub asking for help and a better error message."; + } + }else{ sout << fld_name << " must be from " << min_val << " to " << max_val; - if(!xtra.empty()) sout << ' ' << '(' << xtra << ')'; - showError(sout.str(), "", &me); - return false; } - return true; + if(!xtra.empty()) sout << ' ' << '(' << xtra << ')'; + showError(sout.str(), "", &me); + return false; } bool check_range(cDialog& me,std::string id,bool losing,long min_val,long max_val,std::string fld_name) {