EllanJiang/GameFramework · error · GameFrameworkException

New name ' ' is too long.

Error message

New name '{0}' is too long.

What it means

FileSystem.RenameFile (or similar rename API) validates that the new file name length fits in a single byte, because the file system format stores the name length as a byte. If newName.Length exceeds byte.MaxValue (255), the rename cannot be recorded in the file system header, so the library throws before doing any work.

Solutions

  1. Shorten newName to 255 characters or fewer before calling the rename API.
  2. Assert/guard newName.Length <= byte.MaxValue in calling code and surface a user-facing validation message instead of crashing.
  3. If the desired identifier is inherently long, store the long value as file content or metadata and use a short generated name (e.g. hash) instead.

Example fix

// before
fileSystem.RenameFile("old.dat", veryLongGeneratedName); // throws if > 255 chars
// after
if (veryLongGeneratedName.Length > byte.MaxValue)
    veryLongGeneratedName = Utility.Text.Format("{0}", Utility.Verifier.GetCRC32(...)); // or otherwise shorten
fileSystem.RenameFile("old.dat", veryLongGeneratedName);
Defensive patterns

Strategy: validation

Validate before calling

if (newName == null || newName.Length == 0 || newName.Length > byte.MaxValue)
    throw new ArgumentException("New name must be 1-255 characters.", nameof(newName));

Type guard

static bool IsValidNewName(string newName) => !string.IsNullOrEmpty(newName) && newName.Length <= byte.MaxValue;

Try / catch

try { fileSystem.RenameFile(oldName, newName); }
catch (GameFrameworkException ex) when (ex.Message.StartsWith("New name")) { /* surface a 'name too long' validation error to the user */ }

Prevention

When it happens

Trigger: Calling a public rename method on FileSystem (e.g. RenameFile/RenameData) with a newName whose string length is greater than 255 characters and which passes the earlier 'New name is invalid.' check (non-empty, not equal to oldName is checked after).

Common situations: Programmatically building names from long paths, hashes, GUIDs with prefixes, or concatenating labels/separators until the name exceeds 255 chars; copying a full path instead of a bare file name into the rename call.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


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

Appendix: source

Thrown at GameFramework/FileSystem/FileSystem.cs:1028

        {
            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;
            if (!m_FileDatas.TryGetValue(oldName, out blockIndex))
            {
                return false;
            }

View on GitHub (pinned to d0c010b051)