openclaw/memory/2026-02-03.md
Ubuntu 0214bbc91b Add critical lessons to memory - never repeat these mistakes
Three critical lessons:
1. ALWAYS use `ls -la app/filament/Resources/` first to confirm path
2. NEVER use UnitEnum/BackedEnum imports - they are PHP built-in types
3. STOP and thoroughly diagnose when issues repeat, instead of continuing blindly

These are PHP 8.2 built-in enum types, not classes that need importing.

Reference working code:
- SupplierResource.php works WITHOUT these imports
- Use type declarations directly: string|BackedEnum|null and UnitEnum|string|null
2026-02-03 09:51:11 +08:00

72 lines
2.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 2026-02-03 - 关键错误教训
## 🚨 反复犯的低级错误
### 错误 1: 目录大小写混淆
- **问题**: 项目使用 `app/Filament/` (大写 F我一直修改 `app/filament/` (小写 f
- **影响**: 所有修改都写在错误的目录下,完全无效
- **根本原因**: 没有先检查 `ls -la app/` 确认实际目录结构
- **教训**: 永远先用 `ls` 查看目录结构,**确认正确路径再修改**
### 错误 2: 错误的 import 语句
- **问题**: 一直添加 `use BackedEnum;``use UnitEnum;`
- **事实**: 这些是 PHP 8.2 内置的枚举类型,不是类,**完全不需要 import**
- **影响**: 导致类加载失败,类型检查一直报错
- **根本原因**: 没有仔细阅读现有代码 (SupplierResource.php 可以正常工作,没有这些 import)
- **教训**: **UnitEnum 和 BackedEnum 是 PHP 内置枚举类型,永远不要 import**
### 错误 3: 重复犯同样错误
- **问题**: 用户多次指出问题,我没有真正理解就继续修改
- **影响**: 浪费大量时间,重复犯同样错误
- **根本原因**: 没有停下来彻底诊断,理解根本原因
- **教训**: **当问题重复出现时,立即停下来,彻底诊断,理解根本原因,然后一次性正确修复!**
---
## ✅ 正确的做法
### 1. 确认目录结构
```bash
# 永远先用这个确认路径
ls -la app/Filament/Resources/
```
### 2. 类型声明 (正确)
```php
// 正确 - PHP 8.2 内置枚举,不需要 import
protected static string|BackedEnum|null $navigationIcon = '...';
protected static UnitEnum|string|null $navigationGroup = '...';
```
### 3. 查看现有代码学习
```bash
# 参考可以正常工作的文件
cat app/Filament/Resources/Suppliers/SupplierResource.php | grep "use.*Enum"
# 结果:空,因为不需要 import
```
---
## 📋 检查清单
在修改任何 Filament Resource 文件之前,**必须**检查:
- [ ] 确认正确的目录路径 (`app/Filament/` 不是 `app/filament/`)
- [ ] 参考现有正常工作的代码
- [ ] 确认不需要 `use UnitEnum``use BackedEnum`
- [ ] 使用 `php -l` 检查语法
- [ ] 验证类型声明符合 Filament 4.x 规范
---
## 🔥 切记
1. **永远** 先用 `ls` 查看目录结构
2. **永远** 不要 `use UnitEnum``use BackedEnum`
3. **永远** 当问题重复时,停下来彻底诊断
4. **永远** 从现有正常工作的代码学习
---
美羊羊 🐑