fix-errors
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesefix-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/presubmitThis 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 -- --checkClippy (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 warningsWASM Clippy:
bash
cargo clippy --target wasm32-unknown-unknown --profile release-wasm-debug_assertions --no-depsObjective-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 v2Doc tests:
bash
cargo test --doc当调试特定问题时,可以单独运行各项检查:
Rust格式检查:
bash
cargo fmt -- --checkClippy(全工作区):
bash
cargo clippy --workspace --exclude warp_completer --all-targets --all-features --tests -- -D warnings
cargo clippy -p warp_completer --all-targets --tests -- -D warningsWASM Clippy检查:
bash
cargo clippy --target wasm32-unknown-unknown --profile release-wasm-debug_assertions --no-depsObjective-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 --docRunning 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> --nocaptureCommon Error Types
常见错误类型
Unused Imports
未使用的导入
Remove unused statements identified by the compiler.
use移除编译器识别出的未使用语句。
useUnused Constants
未使用的常量
Remove constants that are defined but never used.
移除已定义但从未使用的常量。
Unknown Imports
未知导入
Add the correct statement for undefined types. Search the codebase to find the correct module path.
use为未定义的类型添加正确的语句。搜索代码库以找到正确的模块路径。
useType Mismatches
类型不匹配
Update function calls to pass arguments of the correct type. Common fixes:
- Use instead of
.as_str()when a.clone()is expected&str - Use when a reference is needed
&value - Use when
.to_string()is expected butStringis provided&str
更新函数调用,传入正确类型的参数。常见修复方法:
- 当需要时,使用
&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 params: pass
boolortruebased on contextfalse - For params: pass
Option<T>as default orNoneif neededSome(value)
当函数新增参数时,更新所有调用位置以传入新参数:
- 对于参数:根据上下文传入
bool或truefalse - 对于参数:默认传入
Option<T>,或根据需要传入NoneSome(value)
Enum Variant Changes
枚举变体变更
When adding a new enum variant, update exhaustive statements:
match- 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 ( target) don't support filesystem operations. Code that uses filesystem APIs must be gated behind the feature flag.
wasm32-unknown-unknownlocal_fsCommon WASM errors:
- Dead code warnings for code only used in non-WASM builds
- Unused code that's only relevant when is available
local_fs - Tests that require filesystem access
Fixes:
Gate tests behind :
local_fsrust
#[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 is enabled:
local_fsrust
#[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-depsWASM构建(目标为)不支持文件系统操作。使用文件系统API的代码必须通过特性标志进行条件编译。
wasm32-unknown-unknownlocal_fs常见WASM错误:
- 仅在非WASM构建中使用的代码出现死代码警告
- 仅在可用时才相关的未使用代码
local_fs - 需要文件系统访问的测试
修复方法:
将测试通过特性标志进行条件编译:
local_fsrust
#[test]
#[cfg(feature = "local_fs")]
fn test_find_git_repo_with_worktree() {
// 使用文件系统操作的测试
}对仅在启用时才使用的类型,条件性允许死代码:
local_fsrust
#[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-depsBest 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 frequently to verify fixes
cargo check - For WASM errors, run WASM clippy to verify the fix
- For complex changes, run relevant tests after fixing
After fixing:
- Always run and
cargo fmtbefore pushingcargo clippy - Run the full presubmit script before opening or updating a PR. Use the skill for more detailed instructions
create-pr - Verify tests pass in the areas you modified
修复前:
- 阅读完整的错误消息以理解根本原因
- 检查多个错误是否相关(修复一个可能解决其他错误)
- 对于trait/类型错误,确认您理解预期类型与实际类型的区别
- 对于WASM错误,检查代码是否需要通过特性标志进行条件编译
local_fs
修复时:
- 当存在多个问题时,一次修复一种类型的错误
- 频繁运行以验证修复效果
cargo check - 对于WASM错误,运行WASM Clippy以验证修复
- 对于复杂变更,修复后运行相关测试
修复后:
- 推送代码前务必运行和
cargo fmtcargo clippy - 创建或更新PR前运行完整的预提交脚本。如需更详细说明,请使用技能
create-pr - 验证您修改的区域测试通过