Speakr is a personal, self-hosted web application designed for transcribing audio recordings
Python
Clean up transcription-failure error display: strip ANSI colour codes from ASR error bodies (backend + frontend), and show a plain 'Transcription Service Error' with helpful guidance for 5xx responses instead of dumping the raw Ray traceback
Murtaza Nasirdf7d86e5f534
diff --git a/src/utils/error_formatting.py b/src/utils/error_formatting.pyindex 591f8ce3..cadb5153 100644--- a/src/utils/error_formatting.py+++ b/src/utils/error_formatting.py@@ -201,6 +201,19 @@ def extract_error_details(error_text: str) -> Dict:return details+# ANSI terminal colour codes some ASR runtimes (e.g. Ray/faster-whisper) inject+# into error bodies. Matches both real ESC sequences and the literal ``[..m``+# form that survives JSON encoding and would otherwise render as garbage in the UI.+_ANSI_RE = re.compile(r'(?:\x1b|\\x1b|\\u001b)\[[0-9;]*m')+++def _strip_ansi(text: str) -> str:+ """Remove ANSI colour codes from an error string (see _ANSI_RE)."""+ if not text:+ return text+ return _ANSI_RE.sub('', text)++def format_error_for_user(error_text: str) -> Dict:"""Transform a technical error message into a user-friendly format.@@ -226,6 +239,9 @@ def format_error_for_user(error_text: str) -> Dict:'is_known': False}+ # Strip terminal colour codes before anything else so pattern matching, the+ # user-facing message, and the technical detail are all free of ANSI noise.+ error_text = _strip_ansi(error_text)error_lower = error_text.lower()# Check against known patterns@@ -257,21 +273,36 @@ def format_error_for_user(error_text: str) -> Dict:if len(clean_message) > 200:clean_message = clean_message[:200] + '...'- # Generate a reasonable title based on error code+ # Generate a reasonable title/message based on error codetitle = 'Processing Error'+ message = clean_message+ guidance = 'If this error persists, try reprocessing the recording or contact support for assistance.'+ icon = 'fa-exclamation-circle'+ error_type = 'unknown'if details['code']:code = details['code']if code.startswith('4'):title = 'Request Error'elif code.startswith('5'):- title = 'Server Error'+ # A 5xx from the transcription service usually carries an internal+ # traceback that means nothing to a user. Replace it with a plain+ # explanation; the raw text stays available under "technical".+ title = 'Transcription Service Error'+ message = 'The transcription service could not process this recording.'+ guidance = (+ 'This is often temporary — try reprocessing. If it keeps failing, the '+ 'recording may contain little or no speech, or the transcription service '+ 'may need attention.'+ )+ icon = 'fa-server'+ error_type = 'service_error'return {'title': title,- 'message': clean_message,- 'guidance': 'If this error persists, try reprocessing the recording or contact support for assistance.',- 'icon': 'fa-exclamation-circle',- 'type': 'unknown',+ 'message': message,+ 'guidance': guidance,+ 'icon': icon,+ 'type': error_type,'technical': error_text,'is_known': False}diff --git a/static/js/app.modular.js b/static/js/app.modular.jsindex 72c171cf..faa3d8a9 100644--- a/static/js/app.modular.js+++ b/static/js/app.modular.js@@ -28,6 +28,14 @@ import { detectPlatform, getAudioCapabilities, enumerateVirtualAudioDevices } frconst SPEAKER_COLOR_COUNT = 16;// Parse transcription text to detect if it's an error message+// Remove ANSI terminal colour codes (real ESC or the literal form that+// survives JSON) that some ASR runtimes inject into error bodies. Cleans errors+// already stored in the database at display time, complementing the backend+// which strips them before storing new ones.+const stripAnsi = (s) => typeof s === 'string'+ ? s.replace(/(?:\x1b|\\x1b|\\u001b)\[[0-9;]*m/g, '')+ : s;+const parseTranscriptionError = (text) => {if (!text) return null;@@ -39,12 +47,12 @@ const parseTranscriptionError = (text) => {const _t = (key, fb) => (window.i18n && window.i18n.t) ? window.i18n.t(key) : fb;return {title: data.t || _t('errors.fallbackTitle', 'Error'),- message: data.m || _t('errors.fallbackMessage', 'An error occurred'),+ message: stripAnsi(data.m) || _t('errors.fallbackMessage', 'An error occurred'),guidance: data.g || '',icon: data.i || 'fa-exclamation-circle',type: data.y || 'unknown',isKnown: data.k || false,- technical: data.d || ''+ technical: stripAnsi(data.d || '')};} catch (e) {console.error('Failed to parse error JSON:', e);@@ -71,6 +79,7 @@ const parseTranscriptionError = (text) => {// Parse unformatted error messages and make them user-friendlyconst parseUnformattedError = (text) => {const _t = (key, fb) => (window.i18n && window.i18n.t) ? window.i18n.t(key) : fb;+ text = stripAnsi(String(text));const lowerText = text.toLowerCase();// Known error patterns