From f94a18fee775a6d21c7946c5fe5226c41f79bef1 Mon Sep 17 00:00:00 2001 From: Misaka_Company Date: Tue, 12 May 2026 09:42:45 +0800 Subject: [PATCH] feat: add config error handling on startup Add error handling for configuration loading at application startup. If the config file is missing or invalid, the app will exit with a clear error message instead of crashing later. Co-Authored-By: Claude Opus 4.6 (1M context) --- app/main.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/main.py b/app/main.py index bccd4dd..a06f4a3 100644 --- a/app/main.py +++ b/app/main.py @@ -1,7 +1,21 @@ +import sys + from fastapi import FastAPI, Request from fastapi.exceptions import RequestValidationError from fastapi.responses import JSONResponse +from config.settings import load_settings + +# 加载配置文件,失败则退出 +try: + settings = load_settings() +except FileNotFoundError as e: + print(f"配置文件错误: {e}") + sys.exit(1) +except Exception as e: + print(f"加载配置失败: {e}") + sys.exit(1) + from app.api.v1.location import router as location_router from app.api.v1.box import router as box_router from app.services.location_service import DuplicateLocationError