clean error msgs in file browser

3clyp50 committed Jan 31, 2026 at 16:14 UTC 6af489904971be8acb07853b8e6cc6b67289746a
2 files changed +25 -2
python/api/edit_work_dir_file.py
+10 -1
@@ -14,6 +14,13 @@ class EditWorkDirFile(ApiHandler):
14 def get_methods(cls):
15 return ["GET", "POST"]
16
17 + def _extract_error_message(self, error_str: str) -> str:
18 + """Extract user-friendly error message from exception string."""
19 + for line in reversed(error_str.split('\n')):
20 + if ': ' in line and ('Exception' in line or 'Error' in line):
21 + return line.split(': ', 1)[1].strip()
22 + return error_str.strip()
23 +
24 async def process(self, input: Input, request: Request) -> Output:
25 try:
26 if request.method == "GET":
@@ -46,7 +53,9 @@ class EditWorkDirFile(ApiHandler):
53
54 return {"ok": True}
55 except Exception as e:
49 - return {"error": str(e)}
56 + # Extract clean error message from exception
57 + # RPC calls may return full tracebacks in exception strings
58 + return {"error": self._extract_error_message(str(e))}
59
60
61 async def load_file(file_path: str) -> dict:
webui/components/modals/file-editor/file-editor-store.js
+15 -1
@@ -71,7 +71,8 @@ const model = {
71 this.isEditLoading = false;
72 this.scheduleEditorInit();
73 } catch (error) {
74 - const message = error?.message || "Failed to load file";
74 + let message = error?.message || "Failed to load file";
75 + message = this._extractErrorMessage(message);
76 this.editError = message;
77 this.isEditLoading = false;
78 window.toastFrontendError(message, "File Edit Error");
@@ -197,6 +198,19 @@ const model = {
198
199 // --- Helpers -------------------------------------------------------------
200
201 + _extractErrorMessage(msg) {
202 + if (typeof msg !== 'string') return msg;
203 + // Extract clean error from traceback strings
204 + const lines = msg.split('\n');
205 + for (let i = lines.length - 1; i >= 0; i--) {
206 + const line = lines[i].trim();
207 + if (line.includes(': ') && /Exception|Error/.test(line)) {
208 + return line.split(': ').slice(1).join(': ').trim();
209 + }
210 + }
211 + return msg;
212 + },
213 +
214 resetEditState() {
215 if (this.editor?.destroy) {
216 this.editor.destroy();