{"record":{"id":"4b92f92f72164a99","repo":"Unity-Technologies/UnityCsReference","slug":"setcodeeditor-does-not-allow-null-editorpath","errorCode":null,"errorMessage":"SetCodeEditor: Does not allow null editorPath","messagePattern":"SetCodeEditor: Does not allow null editorPath","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/CodeEditor/CodeEditor.cs","lineNumber":189,"sourceCode":"\n        private static void AddIfPathExists(string name, string path, Dictionary<string, string> list)\n        {\n            if (list.ContainsKey(path)) return;\n            if (Directory.Exists(path)) list.Add(path, name);\n            else if (File.Exists(path)) list.Add(path, name);\n        }\n\n        [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]\n        public static void SetExternalScriptEditor(string path)\n        {\n            Editor.SetCodeEditor(path);\n        }\n\n        public void SetCodeEditor(string editorPath)\n        {\n            if (editorPath == null)\n            {\n                throw new ArgumentException(\"SetCodeEditor: Does not allow null editorPath\");\n            }\n\n            EditorPrefs.SetString(\"kScriptsDefaultApp\", editorPath);\n            m_CurrentEditor = ComputeCurrentEditor(editorPath);\n            m_CurrentInstallation = GetInstallationForPath(editorPath);\n            m_CurrentEditor.Initialize(editorPath);\n        }\n\n        private IExternalCodeEditor ComputeCurrentEditor(string editorPath)\n        {\n            if (m_ExternalCodeEditors.Count == 0)\n            {\n                TypeCollection collection = TypeCache.GetTypesDerivedFrom<IExternalCodeEditor>();\n                for (int i = 0; i < collection.Count; i++)\n                {\n                    var codeEditorType = collection[i];\n                    if (codeEditorType == typeof(DefaultExternalCodeEditor))\n                        continue;","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/CodeEditor/CodeEditor.cs#L171-L207","documentation":"ArgumentException thrown by CodeEditor.SetCodeEditor when editorPath is null. SetCodeEditor persists the path to EditorPrefs ('kScriptsDefaultApp'), computes the current editor, and initializes it; a null path would corrupt preferences and is rejected. This is the canonical setter for the external script editor preference.","triggerScenarios":"Calling CodeEditor.SetCodeEditor(null), often indirectly via Editor.SetCodeEditor(path) or SetExternalScriptEditor(path) when path is null. Happens when a settings UI commits a null/empty selection or a detection routine yields null.","commonSituations":"Preferences window saving before a path is chosen; automation that resets the script editor to a detected path that returned null; cross-platform code where the path detection fails on a given OS.","solutions":["Validate the path is non-null and points to an existing editor executable before calling SetCodeEditor.","Default to CodeEditor.SystemDefaultPath when no explicit editor is selected.","In UI flows, disable the apply action until a valid path is present."],"exampleFix":"// before\nCodeEditor.SetCodeEditor(detectedPath);\n\n// after\nif (!string.IsNullOrEmpty(detectedPath))\n    CodeEditor.SetCodeEditor(detectedPath);\nelse\n    CodeEditor.SetCodeEditor(CodeEditor.SystemDefaultPath);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(editorPath)) editorPath = CodeEditor.SystemDefaultPath;\nCodeEditor.SetCodeEditor(editorPath);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate the path exists before setting.","Default to SystemDefaultPath when none chosen.","Disable apply in UI until a valid path is present."],"tags":["unity-editor","code-editor","argument-validation","preferences","nullable"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}