{"record":{"id":"2daec2cb73c92be1","repo":"Unity-Technologies/UnityCsReference","slug":"getcodeeditorforpath-does-not-allow-null-editorpa","errorCode":null,"errorMessage":"GetCodeEditorForPath: Does not allow null editorPath","messagePattern":"GetCodeEditorForPath: Does not allow null editorPath","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/CodeEditor/CodeEditor.cs","lineNumber":140,"sourceCode":"                return installation;\n            }\n\n            foreach (var codeEditor in m_ExternalCodeEditors)\n            {\n                if (codeEditor.TryGetInstallationForPath(editorPath, out installation))\n                {\n                    return installation;\n                }\n            }\n            m_DefaultEditor.TryGetInstallationForPath(editorPath, out installation);\n            return installation;\n        }\n\n        public IExternalCodeEditor GetCodeEditorForPath(string editorPath)\n        {\n            if (editorPath == null)\n            {\n                throw new ArgumentException(\"GetCodeEditorForPath: Does not allow null editorPath\");\n            }\n\n            if (editorPath == CodeEditor.SystemDefaultPath)\n            {\n                return m_DefaultEditor;\n            }\n\n            foreach (var codeEditor in m_ExternalCodeEditors)\n            {\n                if (codeEditor.TryGetInstallationForPath(editorPath, out _))\n                {\n                    return codeEditor;\n                }\n            }\n            return m_DefaultEditor;\n        }\n\n        public Dictionary<string, string> GetFoundScriptEditorPaths()","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/CodeEditor/CodeEditor.cs#L122-L158","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Null-check editorPath before calling and substitute CodeEditor.SystemDefaultPath.","Set the script editor preference via CodeEditor.SetCodeEditor before resolving by path.","Surface a clear error to the user (no code editor configured) rather than passing null."],"exampleFix":"// before\nvar editor = CodeEditor.GetCodeEditorForPath(path);\n\n// after\nvar resolved = path ?? CodeEditor.SystemDefaultPath;\nvar editor = CodeEditor.GetCodeEditorForPath(resolved);","handlingStrategy":"validation","validationCode":"if (editorPath == null) editorPath = CodeEditor.SystemDefaultPath;\nvar editor = CodeEditor.GetCodeEditorForPath(editorPath);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Substitute SystemDefaultPath for null paths.","Validate preferences are set before resolution.","Surface a clear 'no editor configured' message to users."],"tags":["unity-editor","code-editor","argument-validation","nullable"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}