fix-errors

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

fix-errors

修复错误

Fix compilation errors, linting issues, and test failures in the warp Rust codebase.
修复warp Rust代码库中的编译错误、代码检查问题和测试失败问题。

Overview

概述

This skill helps resolve common issues encountered during development, including:
  • Compilation errors (unused imports, type mismatches, etc.)
  • Linting failures (clippy warnings)
  • Formatting violations
  • WASM-specific errors
  • Test failures
Before opening or updating a pull request, all presubmit checks must pass.
本技能可帮助解决开发过程中遇到的常见问题,包括:
  • 编译错误(未使用的导入、类型不匹配等)
  • 代码检查失败(clippy警告)
  • 格式违规
  • WASM特定错误
  • 测试失败
在创建或更新拉取请求(PR)之前,所有预提交检查必须通过。

Presubmit Checks

预提交检查

Run all presubmit checks at once:
bash
./script/presubmit
This runs formatting, linting, and all tests. If it passes, you're ready to open a PR.
一次性运行所有预提交检查:
bash
./script/presubmit
该命令会运行格式检查、代码检查以及所有测试。如果检查通过,您就可以创建PR了。

Individual Checks

单独检查

Run checks separately when debugging specific issues:
Rust formatting:
bash
cargo fmt -- --check
Clippy (full workspace):
bash
cargo clippy --workspace --exclude warp_completer --all-targets --all-features --tests -- -D warnings
cargo clippy -p warp_completer --all-targets --tests -- -D warnings
WASM Clippy:
bash
cargo clippy --target wasm32-unknown-unknown --profile release-wasm-debug_assertions --no-deps
Objective-C/C/C++ formatting:
bash
./script/run-clang-format.py -r --extensions 'c,h,cpp,m' ./crates/warpui/src/ ./app/src/
All tests:
bash
cargo nextest run --no-fail-fast --workspace --exclude command-signatures-v2
cargo nextest run -p warp_completer --features v2
Doc tests:
bash
cargo test --doc
当调试特定问题时,可以单独运行各项检查:
Rust格式检查:
bash
cargo fmt -- --check
Clippy(全工作区):
bash
cargo clippy --workspace --exclude warp_completer --all-targets --all-features --tests -- -D warnings
cargo clippy -p warp_completer --all-targets --tests -- -D warnings
WASM Clippy检查:
bash
cargo clippy --target wasm32-unknown-unknown --profile release-wasm-debug_assertions --no-deps
Objective-C/C/C++格式检查:
bash
./script/run-clang-format.py -r --extensions 'c,h,cpp,m' ./crates/warpui/src/ ./app/src/
所有测试:
bash
cargo nextest run --no-fail-fast --workspace --exclude command-signatures-v2
cargo nextest run -p warp_completer --features v2
文档测试:
bash
cargo test --doc

Running Specific Tests

运行特定测试

Single package:
bash
cargo nextest run -p <package_name>
Filter by test name:
bash
cargo nextest run -E 'test(<substring>)'
Specific package with filter:
bash
cargo nextest run -p <package_name> -E 'test(<substring>)'
With output (no capture):
bash
cargo nextest run -p <package> --nocapture
单个包:
bash
cargo nextest run -p <package_name>
按测试名称筛选:
bash
cargo nextest run -E 'test(<substring>)'
带筛选条件的特定包:
bash
cargo nextest run -p <package_name> -E 'test(<substring>)'
显示输出(不捕获):
bash
cargo nextest run -p <package> --nocapture

Common Error Types

常见错误类型

Unused Imports

未使用的导入

Remove unused
use
statements identified by the compiler.
移除编译器识别出的未使用
use
语句。

Unused Constants

未使用的常量

Remove constants that are defined but never used.
移除已定义但从未使用的常量。

Unknown Imports

未知导入

Add the correct
use
statement for undefined types. Search the codebase to find the correct module path.
为未定义的类型添加正确的
use
语句。搜索代码库以找到正确的模块路径。

Type Mismatches

类型不匹配

Update function calls to pass arguments of the correct type. Common fixes:
  • Use
    .as_str()
    instead of
    .clone()
    when a
    &str
    is expected
  • Use
    &value
    when a reference is needed
  • Use
    .to_string()
    when
    String
    is expected but
    &str
    is provided
更新函数调用,传入正确类型的参数。常见修复方法:
  • 当需要
    &str
    时,使用
    .as_str()
    而非
    .clone()
  • 当需要引用时,使用
    &value
  • 当需要
    String
    但提供的是
    &str
    时,使用
    .to_string()

Struct Field Changes

结构体字段变更

When a struct adds/removes fields, update all places where it's constructed or destructured:
  • Struct initialization
  • Pattern matching (
    match
    ,
    if let
    )
  • Destructuring assignments
当结构体添加/移除字段时,更新所有构造或解构该结构体的地方:
  • 结构体初始化
  • 模式匹配(
    match
    if let
  • 解构赋值

Function Signature Changes

函数签名变更

When a function adds a new parameter, update all call sites to provide the new argument:
  • For
    bool
    params: pass
    true
    or
    false
    based on context
  • For
    Option<T>
    params: pass
    None
    as default or
    Some(value)
    if needed
当函数新增参数时,更新所有调用位置以传入新参数:
  • 对于
    bool
    参数:根据上下文传入
    true
    false
  • 对于
    Option<T>
    参数:默认传入
    None
    ,或根据需要传入
    Some(value)

Enum Variant Changes

枚举变体变更

When adding a new enum variant, update exhaustive
match
statements:
  • Add a new match arm with appropriate handling
  • Mirror the implementation pattern of similar variants
当添加新的枚举变体时,更新穷尽式
match
语句:
  • 添加新的match分支并进行适当处理
  • 参考类似变体的实现模式

Incorrect Trait Implementation

错误的 trait 实现

Fix trait implementations that return the wrong type or don't satisfy trait bounds.
修复返回错误类型或不满足trait约束的trait实现。

WASM-Specific Errors

WASM特定错误

WASM builds (
wasm32-unknown-unknown
target) don't support filesystem operations. Code that uses filesystem APIs must be gated behind the
local_fs
feature flag.
Common WASM errors:
  • Dead code warnings for code only used in non-WASM builds
  • Unused code that's only relevant when
    local_fs
    is available
  • Tests that require filesystem access
Fixes:
Gate tests behind
local_fs
:
rust
#[test]
#[cfg(feature = "local_fs")]
fn test_find_git_repo_with_worktree() {
    // Test that uses filesystem operations
}
Conditionally allow dead code for types only used when
local_fs
is enabled:
rust
#[cfg_attr(not(feature = "local_fs"), allow(dead_code))]
#[derive(Clone, EnumDiscriminants, Serialize)]
pub enum ExampleType {
    // Variants only used when local_fs is enabled
    Variant1,
    Variant2,
    Variant3,
}
WASM errors are discovered by running:
bash
cargo clippy --target wasm32-unknown-unknown --profile release-wasm-debug_assertions --no-deps
WASM构建(目标为
wasm32-unknown-unknown
)不支持文件系统操作。使用文件系统API的代码必须通过
local_fs
特性标志进行条件编译。
常见WASM错误:
  • 仅在非WASM构建中使用的代码出现死代码警告
  • 仅在
    local_fs
    可用时才相关的未使用代码
  • 需要文件系统访问的测试
修复方法:
将测试通过
local_fs
特性标志进行条件编译:
rust
#[test]
#[cfg(feature = "local_fs")]
fn test_find_git_repo_with_worktree() {
    // 使用文件系统操作的测试
}
对仅在
local_fs
启用时才使用的类型,条件性允许死代码:
rust
#[cfg_attr(not(feature = "local_fs"), allow(dead_code))]
#[derive(Clone, EnumDiscriminants, Serialize)]
pub enum ExampleType {
    // 仅在local_fs启用时使用的变体
    Variant1,
    Variant2,
    Variant3,
}
WASM错误可通过运行以下命令发现:
bash
cargo clippy --target wasm32-unknown-unknown --profile release-wasm-debug_assertions --no-deps

Best Practices

最佳实践

Before fixing:
  • Read the full error message to understand the root cause
  • Check if multiple errors are related (fixing one may resolve others)
  • For trait/type errors, verify you understand the expected vs actual types
  • For WASM errors, check if code needs to be gated behind
    local_fs
When fixing:
  • Fix one error type at a time when there are multiple issues
  • Run
    cargo check
    frequently to verify fixes
  • For WASM errors, run WASM clippy to verify the fix
  • For complex changes, run relevant tests after fixing
After fixing:
  • Always run
    cargo fmt
    and
    cargo clippy
    before pushing
  • Run the full presubmit script before opening or updating a PR. Use the
    create-pr
    skill for more detailed instructions
  • Verify tests pass in the areas you modified
修复前:
  • 阅读完整的错误消息以理解根本原因
  • 检查多个错误是否相关(修复一个可能解决其他错误)
  • 对于trait/类型错误,确认您理解预期类型与实际类型的区别
  • 对于WASM错误,检查代码是否需要通过
    local_fs
    特性标志进行条件编译
修复时:
  • 当存在多个问题时,一次修复一种类型的错误
  • 频繁运行
    cargo check
    以验证修复效果
  • 对于WASM错误,运行WASM Clippy以验证修复
  • 对于复杂变更,修复后运行相关测试
修复后:
  • 推送代码前务必运行
    cargo fmt
    cargo clippy
  • 创建或更新PR前运行完整的预提交脚本。如需更详细说明,请使用
    create-pr
    技能
  • 验证您修改的区域测试通过