Unity-Technologies/UnityCsReference · error · ArgumentException

GetCodeEditorForPath: Does not allow null editorPath

Error message

GetCodeEditorForPath: Does not allow null editorPath

What it means

ArgumentException thrown by CodeEditor.GetCodeEditorForPath when editorPath is null. The method resolves the IExternalCodeEditor for a path (with a SystemDefaultPath special case), iterating m_ExternalCodeEditors and falling back to m_DefaultEditor; null is explicitly rejected before lookup.

Source

Thrown at Editor/Mono/CodeEditor/CodeEditor.cs:140

                return installation;
            }

            foreach (var codeEditor in m_ExternalCodeEditors)
            {
                if (codeEditor.TryGetInstallationForPath(editorPath, out installation))
                {
                    return installation;
                }
            }
            m_DefaultEditor.TryGetInstallationForPath(editorPath, out installation);
            return installation;
        }

        public IExternalCodeEditor GetCodeEditorForPath(string editorPath)
        {
            if (editorPath == null)
            {
                throw new ArgumentException("GetCodeEditorForPath: Does not allow null editorPath");
            }

            if (editorPath == CodeEditor.SystemDefaultPath)
            {
                return m_DefaultEditor;
            }

            foreach (var codeEditor in m_ExternalCodeEditors)
            {
                if (codeEditor.TryGetInstallationForPath(editorPath, out _))
                {
                    return codeEditor;
                }
            }
            return m_DefaultEditor;
        }

        public Dictionary<string, string> GetFoundScriptEditorPaths()

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Null-check editorPath before calling and substitute CodeEditor.SystemDefaultPath.
  2. Set the script editor preference via CodeEditor.SetCodeEditor before resolving by path.
  3. Surface a clear error to the user (no code editor configured) rather than passing null.

Example fix

// before
var editor = CodeEditor.GetCodeEditorForPath(path);

// after
var resolved = path ?? CodeEditor.SystemDefaultPath;
var editor = CodeEditor.GetCodeEditorForPath(resolved);
Defensive patterns

Strategy: validation

Validate before calling

if (editorPath == null) editorPath = CodeEditor.SystemDefaultPath;
var editor = CodeEditor.GetCodeEditorForPath(editorPath);

Prevention

When it happens

Trigger: Calling CodeEditor.GetCodeEditorForPath(null). Happens when the path is sourced from preferences/detection that returned null, or when a caller forgets to supply the path.

Common situations: Unset external script editor preference; tooling that reads the editor path from a config that may be missing; migration where the pref key differs between Unity versions.

Related errors


AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13). Data as JSON: /api/errors/2daec2cb73c92be1. Report an issue: GitHub.