除錯指南
標註項目的除錯標誌、日誌選項和故障排除技巧。
Potato 提供了多個命令列標誌和配置選項,幫助除錯和測試標註項目。這些在開發和故障排除過程中非常有用。
伺服器配置
你可以在 YAML 配置檔案中直接配置伺服器設定:
yaml
server:
port: 8000 # Port to run on (default: 8000)
host: "0.0.0.0" # Host to bind to (default: 0.0.0.0)
debug: false # Enable Flask debug mode (default: false)注意: CLI 標誌優先於配置檔案中的值。例如,-p 9000 將覆蓋 server.port: 8000。
除錯標誌
--debug
以除錯模式啟動 Potato,使用簡化的身份驗證。
bash
potato start config.yaml --debug效果:
- 跳過正常登入要求
- 啟用詳細日誌
- 適用於快速測試配置更改
--debug-log
控制系統不同部分的除錯日誌輸出。
bash
potato start config.yaml --debug --debug-log=all選項:
| 值 | 描述 |
|---|---|
all | 同時啟用 UI(前端)和伺服器(後端)的日誌 |
ui | 僅啟用前端 JavaScript 控制台日誌 |
server | 僅啟用後端 Python 日誌 |
none | 停用所有除錯日誌 |
示例:
bash
# Debug frontend issues (JavaScript errors, UI state)
potato start config.yaml --debug --debug-log=ui
# Debug backend issues (API calls, data processing)
potato start config.yaml --debug --debug-log=server
# Full debugging (both frontend and backend)
potato start config.yaml --debug --debug-log=all
# Quiet mode - minimal output
potato start config.yaml --debug --debug-log=none--debug-phase
跳過早期階段,直接進入特定階段或頁面。這對於測試標註工作流的特定部分非常有用。
bash
potato start config.yaml --debug --debug-phase=annotation要求: 必須同時設定 --debug 標誌。
有效階段名稱:
login- 登入頁面consent- 知情同意表單prestudy- 研究前調查instructions- 說明頁面training- 培訓階段annotation- 主要標註階段poststudy- 研究後調查done- 完成頁面
示例:
bash
# Jump directly to annotation (most common use case)
potato start config.yaml --debug --debug-phase=annotation
# Test post-study survey
potato start config.yaml --debug --debug-phase=poststudy
# Test a specific named page
potato start config.yaml --debug --debug-phase=my_custom_survey工作原理:
- 自動建立並登入名為
debug_user的使用者 - 跳過指定階段之前的所有階段
- 使用者狀態設定為已完成所有先前階段
組合除錯標誌
可以組合標誌用於不同的除錯場景:
bash
# Quick annotation testing with minimal noise
potato start config.yaml --debug --debug-phase=annotation --debug-log=none
# Full debugging of annotation phase
potato start config.yaml --debug --debug-phase=annotation --debug-log=all
# Debug only backend while testing post-study
potato start config.yaml --debug --debug-phase=poststudy --debug-log=server其他有用標誌
--verbose / -v
啟用詳細輸出用於常規操作日誌。
bash
potato start config.yaml -v--veryVerbose
啟用非常詳細的輸出,包含詳細的內部狀態資訊。
bash
potato start config.yaml --veryVerbose--port / -p
在指定埠執行(在執行多個實例時很有用)。
bash
potato start config.yaml -p 8080瀏覽器開發者工具
除了命令列標誌,還可以使用瀏覽器開發者工具進行除錯:
- 控制台:檢視 JavaScript 日誌和錯誤(F12 或 Cmd+Option+I)
- 網路:監控前後端之間的 API 呼叫
- 元素:檢查 DOM 和 CSS 樣式
- 應用程式:檢查會話儲存和 cookie
重新啟用控制台日誌
如果通過 --debug-log=server 或 --debug-log=none 停用了 UI 日誌,可以在瀏覽器控制台中重新啟用:
javascript
enableUIDebug();常見除錯場景
測試新的標註模式
bash
# Skip to annotation with full logging
potato start config.yaml --debug --debug-phase=annotation --debug-log=all除錯 API 問題
bash
# Server-only logging to focus on backend
potato start config.yaml --debug --debug-log=server然後使用瀏覽器網路標籤頁檢查請求/響應資料。
測試使用者流程
bash
# Start from the beginning with UI logging
potato start config.yaml --debug --debug-log=ui效能測試
bash
# Minimal logging overhead
potato start config.yaml --debug --debug-phase=annotation --debug-log=none故障排除
"debug-phase requires --debug flag"
--debug-phase 選項僅在同時指定 --debug 時有效:
bash
# Wrong
potato start config.yaml --debug-phase=annotation
# Correct
potato start config.yaml --debug --debug-phase=annotation階段未找到
如果指定的階段在配置中不存在,請檢查:
- 階段名稱拼寫正確
- 階段已在 YAML 配置中定義
- 對於自定義頁面,使用配置中的確切頁面名稱
延伸閱讀
- Preview CLI - 不執行伺服器即可驗證配置
- 使用者模擬器 - 使用模擬使用者進行自動化測試
- 本地開發 - 開發環境設定
有關實現細節,請參閱原始碼文件。