CoplayDev/unity-mcp · error · ArgumentException

Source path cannot be empty.

Error message

Source path cannot be empty.

What it means

Thrown by PackageDeploymentService.ValidateSource (throwOnError=true) when sourcePath is null or empty. ValidateSource is the shared pre-check for package deployment; in throwOnError mode each failure throws ArgumentException. An empty source means no folder was supplied to the deploy flow.

Source

Thrown at MCPForUnity/Editor/Services/PackageDeploymentService.cs:221

            string stamp = DateTime.Now.ToString("yyyyMMdd_HHmmss");
            string backupPath = Path.Combine(backupRoot, $"backup_{stamp}");

            if (Directory.Exists(backupPath))
            {
                FileUtil.DeleteFileOrDirectory(backupPath);
            }

            FileUtil.CopyFileOrDirectory(targetPath, backupPath);
            return backupPath;
        }

        private static string ValidateSource(string sourcePath, bool throwOnError = true)
        {
            if (string.IsNullOrEmpty(sourcePath))
            {
                if (throwOnError)
                {
                    throw new ArgumentException("Source path cannot be empty.");
                }

                return "Source path is empty.";
            }

            if (!Directory.Exists(sourcePath))
            {
                if (throwOnError)
                {
                    throw new ArgumentException("Selected folder does not exist.");
                }

                return "Selected folder does not exist.";
            }

            bool hasEditor = Directory.Exists(Path.Combine(sourcePath, "Editor"));
            bool hasRuntime = Directory.Exists(Path.Combine(sourcePath, "Runtime"));

View on GitHub (pinned to c21bf496bc)

Solutions

  1. Supply the package source folder path (the folder containing Editor/ and Runtime/).
  2. If calling programmatically, null-check sourcePath before invoking ValidateSource.
  3. In the UI, ensure the folder picker actually returned a selection.

Example fix

// before
ValidateSource(sourcePath, throwOnError: true); // throws if sourcePath == null

// after
if (string.IsNullOrEmpty(sourcePath)) return Error("Pick a package source folder.");
ValidateSource(sourcePath, throwOnError: true);
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrEmpty(sourcePath))
    return ErrorResponse("Pick a package source folder before deploying.");
ValidateSource(sourcePath, throwOnError: true);

Type guard

static bool IsValidSourcePath(string p) => !string.IsNullOrEmpty(p);

Try / catch

try { ValidateSource(sourcePath, throwOnError: true); }
catch (ArgumentException ex) when (ex.Message.Contains("empty"))
{ /* prompt the user to pick a folder */ }

Prevention

When it happens

Trigger: DeployPackage/ValidateSource called with null or empty string; the UI folder-selection field was left blank or returned null.

Common situations: Programmatic call with a null variable; UI picker cancelled and returned empty; a pipeline step forgot to set the path.

Related errors


AI-assisted analysis of CoplayDev/unity-mcp@c21bf496bc (2026-08-13). Data as JSON: /api/errors/3fcf5101f9325d98. Report an issue: GitHub.