EllanJiang/GameFramework · error · GameFrameworkException

New name is invalid.

Error message

New name is invalid.

What it means

FileSystem.RenameFile(string oldName, string newName) throws this when newName is null or empty. The new name is what gets written into the file system's name table, so an empty replacement is rejected up front.

Solutions

  1. Pass a non-null, non-empty newName to RenameFile.
  2. Validate the new name (string.IsNullOrWhiteSpace) before invoking; prompt the user again if empty.
  3. Keep newName within byte.MaxValue characters as well, since a separate length check follows immediately.

Example fix

// before
fileSystem.RenameFile(oldName, renameInput.text);
// after
if (!string.IsNullOrWhiteSpace(renameInput.text) && renameInput.text.Length <= byte.MaxValue)
{
    fileSystem.RenameFile(oldName, renameInput.text);
}
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrWhiteSpace(newName)) return false; // or re-prompt
if (newName.Length > byte.MaxValue) return false;

Try / catch

try { fs.RenameFile(oldName, newName); }
catch (GameFrameworkException ex) when (ex.Message == "New name is invalid.") { /* re-prompt for a valid name */ }

Prevention

When it happens

Trigger: Calling RenameFile(oldName, null) or RenameFile(oldName, ""), typically when the new name comes from an empty text field, a cancelled input dialog, or a variable that was never populated.

Common situations: A rename dialog returns an empty string when the user confirms without typing; scripted batch renames read the new names from a file where some lines are blank.

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/a0588f61761ad4a0. Report an issue: GitHub.

Appendix: source

Thrown at GameFramework/FileSystem/FileSystem.cs:1023

        /// </summary>
        /// <param name="oldName">要重命名的文件名称。</param>
        /// <param name="newName">重命名后的文件名称。</param>
        /// <returns>是否重命名指定文件成功。</returns>
        public bool RenameFile(string oldName, string newName)
        {
            if (m_Access != FileSystemAccess.Write && m_Access != FileSystemAccess.ReadWrite)
            {
                throw new GameFrameworkException("File system is not writable.");
            }

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

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

            if (newName.Length > byte.MaxValue)
            {
                throw new GameFrameworkException(Utility.Text.Format("New name '{0}' is too long.", newName));
            }

            if (oldName == newName)
            {
                return true;
            }

            if (m_FileDatas.ContainsKey(newName))
            {
                return false;
            }

            int blockIndex = 0;

View on GitHub (pinned to d0c010b051)