CoplayDev/unity-mcp · error · Exception
Failed to write config file '{path}': {ex.Message}
Error message
Failed to write config file '{path}': {ex.Message} What it means
McpConfigurationHelper writes the config atomically: it backs up the original, writes a temp file, then replaces the target. If any step throws, the catch block restores the backup (only if the final write did not complete) and re-throws a generic Exception whose message embeds the original error and whose InnerException is the real cause. The 'finally' cleans up temp/backup files defensively.
Source
Thrown at MCPForUnity/Editor/Helpers/McpConfigurationHelper.cs:274
}
catch { }
File.Move(path, backup);
}
File.Move(tmp, path);
writeDone = true;
}
}
catch (Exception ex)
{
try
{
if (!writeDone && File.Exists(backup))
{
try { File.Copy(backup, path, true); } catch { }
}
}
catch { }
throw new Exception($"Failed to write config file '{path}': {ex.Message}", ex);
}
finally
{
try { if (File.Exists(tmp)) File.Delete(tmp); } catch { }
try { if (writeDone && File.Exists(backup)) File.Delete(backup); } catch { }
}
}
}
}
View on GitHub (pinned to c21bf496bc)
Solutions
- Close any editor or process holding the config file open, then retry.
- Ensure write permission on the config path and that the disk has free space.
- Inspect the InnerException for the true underlying error rather than the wrapper message.
- Avoid running two instances that write the same config concurrently.
Defensive patterns
Strategy: retry
Validate before calling
// Pre-check the config path is writable before attempting the atomic write.
string dir = Path.GetDirectoryName(path);
if (!Directory.Exists(dir)) Directory.CreateDirectory(dir);
string probe = Path.Combine(dir, $".writeprobe_{Guid():N}");
File.WriteAllText(probe, ""); File.Delete(probe); Try / catch
for (int attempt = 0; attempt < 3; attempt++)
{
try { McpConfigurationHelper.WriteConfig(path, json); break; }
catch (Exception ex) when (IsTransientFileError(ex))
{
if (attempt == 2) throw;
await Task.Delay(250 * (attempt + 1));
}
}
// Inspect ex.InnerException for the real cause when rethrown. Prevention
- Do not keep the config file open in another editor while the tool writes it.
- Avoid two processes writing the same config concurrently.
- Check InnerException for the underlying IO error when this wrapper fires.
When it happens
Trigger: The config file is locked by another process; the disk is full; the path is read-only or permission-denied; the path exceeds OS length limits; antivirus quarantines the temp file mid-write.
Common situations: Config file left open in a text editor; another Unity/editor instance holding a write lock; a read-only project checkout; concurrent writes from two processes to the same config; transient AV interference.
Related errors
- Could not generate a unique screenshot filename for '{fullPa
- The selected uvx executable does not exist
- The selected Claude CLI executable does not exist
- Install Dir contains unmanaged files. Please choose an empty
- Install Dir is invalid and cannot be resolved: {installDir}
AI-assisted analysis of CoplayDev/unity-mcp@c21bf496bc (2026-08-13).
Data as JSON: /api/errors/7351febf7017d295.
Report an issue: GitHub.