EllanJiang/GameFramework · error · GameFrameworkException
Old name is invalid.
Error message
Old name is invalid.
What it means
FileSystem.RenameFile(string oldName, string newName) throws this when oldName is null or empty. oldName identifies the stored file to rename; without it the library cannot locate a target and rejects the call immediately.
Solutions
- Pass a non-null, non-empty oldName to RenameFile.
- Validate with string.IsNullOrWhiteSpace before calling, and skip or warn when empty.
- Ensure the file actually exists (GetFileInfo(name).IsValid) before renaming to avoid confusion with other failure modes.
Example fix
// before
fileSystem.RenameFile(selectedName, newName);
// after
if (!string.IsNullOrWhiteSpace(selectedName))
{
fileSystem.RenameFile(selectedName, newName);
} Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrWhiteSpace(oldName)) return false; if (!fs.GetFileInfo(oldName).IsValid) return false; // nothing to rename
Try / catch
try { fs.RenameFile(oldName, newName); }
catch (GameFrameworkException ex) when (ex.Message == "Old name is invalid.") { /* log empty source name */ } Prevention
- Guard tool/UI code paths where selection can be empty.
- Validate manifest-derived names for blank entries before batch renames.
- Check file existence with GetFileInfo before renaming to avoid masking other issues.
When it happens
Trigger: Calling RenameFile(null, newName) or RenameFile("", newName), usually from an unassigned variable, an empty selection in a tool UI, or a lookup that defaulted to empty.
Common situations: Editor tool passes the currently selected file's name but nothing is selected; a filename parsed from a manifest line was empty because of a trailing separator or format change.
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
- New name is invalid.
- Entity group name is invalid.
- Offset is invalid.
- Length is invalid.
- Max file count is invalid.
AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15).
Data as JSON: /api/errors/0b0f8dce7d86f573.
Report an issue: GitHub.
Appendix: source
Thrown at GameFramework/FileSystem/FileSystem.cs:1018
}
}
/// <summary>
/// 重命名指定文件。
/// </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))View on GitHub (pinned to d0c010b051)