From 0cc331d1c60341bb06b78ceeecfb2db86179c93e Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Mon, 29 Jun 2026 05:46:51 -0500 Subject: [PATCH] refac --- backend/open_webui/constants.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/backend/open_webui/constants.py b/backend/open_webui/constants.py index 132f3ac19a..c4d6b8f3db 100644 --- a/backend/open_webui/constants.py +++ b/backend/open_webui/constants.py @@ -1,8 +1,29 @@ from __future__ import annotations +import errno from enum import Enum +_ERRNO_MESSAGES = { + errno.ENAMETOOLONG: 'File name is too long.', + errno.ENOSPC: 'The server is out of storage space.', + errno.EDQUOT: 'Server storage quota exceeded.', + errno.EACCES: 'Server storage is not writable.', + errno.EPERM: 'Server storage is not writable.', + errno.EROFS: 'Server storage is not writable.', +} + + +def _error_message(err='', fallback='') -> str: + if not err: + return 'Something went wrong :/' + if isinstance(err, OSError) and err.errno in _ERRNO_MESSAGES: + return f'[ERROR: {_ERRNO_MESSAGES[err.errno]}]' + if isinstance(err, Exception): + return f'[ERROR: {fallback}]' if fallback else 'Something went wrong :/' + return f'[ERROR: {err}]' + + class MESSAGES(str, Enum): DEFAULT = lambda msg='': f'{msg if msg else ""}' MODEL_ADDED = lambda model='': f"The model '{model}' has been added successfully." @@ -18,7 +39,7 @@ class ERROR_MESSAGES(str, Enum): def __str__(self) -> str: return super().__str__() - DEFAULT = lambda err='': f'{"Something went wrong :/" if err == "" else "[ERROR: " + str(err) + "]"}' + DEFAULT = _error_message ENV_VAR_NOT_FOUND = 'Required environment variable not found. Terminating now.' CREATE_USER_ERROR = 'Oops! Something went wrong while creating your account. Please try again later. If the issue persists, contact support for assistance.' DELETE_USER_ERROR = 'Oops! Something went wrong. We encountered an issue while trying to delete the user. Please give it another shot.'