Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

fix: Add error tracing to template install endpoint

Juan Denisbac265d80aa0
diff --git a/backend/app/api/templates.py b/backend/app/api/templates.py
index e56568db..140ced77 100644
--- a/backend/app/api/templates.py
+++ b/backend/app/api/templates.py
@@ -123,33 +123,40 @@ def get_template(template_id):
@admin_required
def install_template(template_id):
"""Install a template as a new application."""
- current_user_id = get_jwt_identity()
- data = request.get_json()
-
- if not data:
- return jsonify({'error': 'No data provided'}), 400
-
- app_name = data.get('app_name')
- if not app_name:
- return jsonify({'error': 'app_name is required'}), 400
-
- # Validate app name
- import re
- if not re.match(r'^[a-z0-9][a-z0-9-]*[a-z0-9]$', app_name) or len(app_name) < 3:
- return jsonify({
- 'error': 'App name must be lowercase alphanumeric with hyphens, at least 3 characters'
- }), 400
-
- user_variables = data.get('variables', {})
-
- result = TemplateService.install_template(
- template_id=template_id,
- app_name=app_name,
- user_variables=user_variables,
- user_id=current_user_id
- )
-
- return jsonify(result), 201 if result.get('success') else 400
+ try:
+ current_user_id = get_jwt_identity()
+ data = request.get_json()
+
+ if not data:
+ return jsonify({'error': 'No data provided'}), 400
+
+ app_name = data.get('app_name')
+ if not app_name:
+ return jsonify({'error': 'app_name is required'}), 400
+
+ # Validate app name
+ import re
+ if not re.match(r'^[a-z0-9][a-z0-9-]*[a-z0-9]$', app_name) or len(app_name) < 3:
+ return jsonify({
+ 'error': 'App name must be lowercase alphanumeric with hyphens, at least 3 characters'
+ }), 400
+
+ user_variables = data.get('variables', {})
+
+ result = TemplateService.install_template(
+ template_id=template_id,
+ app_name=app_name,
+ user_variables=user_variables,
+ user_id=current_user_id
+ )
+
+ return jsonify(result), 201 if result.get('success') else 400
+
+ except Exception as e:
+ import traceback
+ error_trace = traceback.format_exc()
+ print(f"Template install error: {error_trace}")
+ return jsonify({'error': str(e), 'trace': error_trace}), 500
@templates_bp.route('/validate-install', methods=['POST'])
diff --git a/backend/app/services/template_service.py b/backend/app/services/template_service.py
index 86896120..40baf52a 100644
--- a/backend/app/services/template_service.py
+++ b/backend/app/services/template_service.py
@@ -440,9 +440,12 @@ class TemplateService:
}
except Exception as e:
+ import traceback
+ error_trace = traceback.format_exc()
+ print(f"Template install service error: {error_trace}")
if os.path.exists(app_path):
shutil.rmtree(app_path)
- return {'success': False, 'error': str(e)}
+ return {'success': False, 'error': str(e), 'trace': error_trace}
@classmethod
def _run_script(cls, script: str, cwd: str, variables: Dict) -> Dict: