Skip to content

调试指南

标注项目的调试标志、日志选项和故障排除技巧。

调试指南

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

浏览器开发者工具

除了命令行标志,还可以使用浏览器开发者工具进行调试:

  1. 控制台:查看 JavaScript 日志和错误(F12 或 Cmd+Option+I)
  2. 网络:监控前后端之间的 API 调用
  3. 元素:检查 DOM 和 CSS 样式
  4. 应用程序:检查会话存储和 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 配置中定义
  • 对于自定义页面,使用配置中的确切页面名称

延伸阅读

有关实现细节,请参阅源代码文档