Skip to content

Introduce ruff for codestyle and linting#356

Closed
kofrezo wants to merge 11 commits into
mainfrom
dk_code_cleanup
Closed

Introduce ruff for codestyle and linting#356
kofrezo wants to merge 11 commits into
mainfrom
dk_code_cleanup

Conversation

@kofrezo

@kofrezo kofrezo commented Apr 30, 2024

Copy link
Copy Markdown
Contributor

No description provided.

Comment thread serveradmin/resources/views.py Fixed
'status': 'error',
'message': str(error)
}))
return HttpResponse(json.dumps({'status': 'error', 'message': str(error)}))

Check warning

Code scanning / CodeQL

Information exposure through an exception

[Stack trace information](1) flows to this location and may be exposed to an external user.

Copilot Autofix

AI over 1 year ago

To fix the problem, we should modify the code to log the detailed error message on the server and return a generic error message to the user. This approach ensures that sensitive information is not exposed to the user while still providing developers with the necessary details to debug the issue.

  1. Import the logging module to enable logging of error messages.
  2. Replace the return statement on line 167 to log the error message and return a generic error message to the user.
Suggested changeset 1
serveradmin/servershell/views.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/serveradmin/servershell/views.py b/serveradmin/servershell/views.py
--- a/serveradmin/servershell/views.py
+++ b/serveradmin/servershell/views.py
@@ -9,3 +9,3 @@
 from itertools import chain, islice
-
+import logging
 from django.contrib import messages
@@ -166,3 +166,4 @@
     except (DatatypeError, ObjectDoesNotExist, ValidationError) as error:
-        return HttpResponse(json.dumps({'status': 'error', 'message': str(error)}))
+        logging.error("An error occurred: %s", str(error))
+        return HttpResponse(json.dumps({'status': 'error', 'message': 'An internal error has occurred!'}))
 
EOF
@@ -9,3 +9,3 @@
from itertools import chain, islice

import logging
from django.contrib import messages
@@ -166,3 +166,4 @@
except (DatatypeError, ObjectDoesNotExist, ValidationError) as error:
return HttpResponse(json.dumps({'status': 'error', 'message': str(error)}))
logging.error("An error occurred: %s", str(error))
return HttpResponse(json.dumps({'status': 'error', 'message': 'An internal error has occurred!'}))

Copilot is powered by AI and may make mistakes. Always verify output.
@kofrezo kofrezo force-pushed the dk_code_cleanup branch 3 times, most recently from d3c6121 to b341557 Compare March 19, 2025 09:46
@kofrezo kofrezo self-assigned this Mar 19, 2025
@kofrezo kofrezo force-pushed the dk_code_cleanup branch 2 times, most recently from 4d4d73b to 987e41a Compare March 19, 2025 12:54
@kofrezo kofrezo changed the title Reformat and lint codebase with ruff Introduce ruff for codestyle and linting Mar 19, 2025
@kofrezo kofrezo marked this pull request as ready for review March 19, 2025 13:26
@kofrezo

kofrezo commented Mar 19, 2025

Copy link
Copy Markdown
Contributor Author

Running this for some time on staging to ensure it breaks nothing.

@kofrezo kofrezo closed this Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants