EllanJiang/GameFramework · error · GameFrameworkException

Setting name is invalid.

Error message

Setting name is invalid.

What it means

SettingManager.HasSetting throws 'Setting name is invalid.' when the settingName argument is null or an empty string, after the helper itself has passed the null check. The library requires a non-empty setting name to look up a configuration entry.

Solutions

  1. Guard the name before calling: skip the lookup or substitute a default key when string.IsNullOrEmpty(settingName).
  2. Fix the upstream source of the empty key (missing constant, empty split segment, bad deserialization).
  3. Define setting names as constants or an enum-derived string map to avoid empty literals.

Example fix

// before
bool has = m_SettingManager.HasSetting(playerKey); // playerKey == ""
// after
if (!string.IsNullOrEmpty(playerKey))
{
    bool has = m_SettingManager.HasSetting(playerKey);
}
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrEmpty(settingName)) return false; // or substitute a default key
bool has = SettingManager.HasSetting(settingName);

Type guard

static bool IsValidSettingName(string name) => !string.IsNullOrEmpty(name);

Try / catch

try { has = m_SettingManager.HasSetting(name); }
catch (GameFrameworkException ex) when (ex.Message == "Setting name is invalid.")
{
    has = false; // treat invalid name as 'not present'
}

Prevention

When it happens

Trigger: Calling SettingManager.HasSetting(null) or HasSetting("") — typically from a variable that was never assigned or an empty result of another lookup.

Common situations: A settings key constant deleted or misspelled so a variable defaults to null; string parsing (e.g. Split) returning an empty segment; deserialized config objects with missing key fields.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15). Data as JSON: /api/errors/8323738d8faf8835. Report an issue: GitHub.

Appendix: source

Thrown at GameFramework/Setting/SettingManager.cs:145

            m_SettingHelper.GetAllSettingNames(results);
        }

        /// <summary>
        /// 检查是否存在指定游戏配置项。
        /// </summary>
        /// <param name="settingName">要检查游戏配置项的名称。</param>
        /// <returns>指定的游戏配置项是否存在。</returns>
        public bool HasSetting(string settingName)
        {
            if (m_SettingHelper == null)
            {
                throw new GameFrameworkException("Setting helper is invalid.");
            }

            if (string.IsNullOrEmpty(settingName))
            {
                throw new GameFrameworkException("Setting name is invalid.");
            }

            return m_SettingHelper.HasSetting(settingName);
        }

        /// <summary>
        /// 移除指定游戏配置项。
        /// </summary>
        /// <param name="settingName">要移除游戏配置项的名称。</param>
        /// <returns>是否移除指定游戏配置项成功。</returns>
        public bool RemoveSetting(string settingName)
        {
            if (m_SettingHelper == null)
            {
                throw new GameFrameworkException("Setting helper is invalid.");
            }

            if (string.IsNullOrEmpty(settingName))

View on GitHub (pinned to d0c010b051)