.cursor/skills/error-handling-patterns/SKILL.md
--- name: error-handling-patterns description: Enforces comprehensive error handling: explicit catch blocks, user-friendly messages, Result/Either patterns. Use when writing async code, service methods, or handling exceptions. --- # Error Handling Patterns ## Mandatory Rules **✅ ALWAYS handle errors explicitly** - never silently swallow exceptions **✅ Use try-catch blocks** for async operations that can fail **✅ Provide user-friendly error messages** in UI **✅ Log errors with context** using
npx skillsauth add avra-cadavra/avrai .cursor/skills/error-handling-patternsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
✅ ALWAYS handle errors explicitly - never silently swallow exceptions
✅ Use try-catch blocks for async operations that can fail
✅ Provide user-friendly error messages in UI
✅ Log errors with context using developer.log()
❌ NEVER use empty catch blocks without logging
try {
await operation();
} on SpecificException catch (e) {
developer.log('Operation failed', error: e, name: 'ServiceName');
// Handle specific error
} catch (e, st) {
developer.log('Unexpected error', error: e, stackTrace: st, name: 'ServiceName');
// Handle generic error
}
Always handle errors in async methods:
Future<Result<String>> fetchData() async {
try {
final data = await repository.fetch();
return Result.success(data);
} on NetworkException catch (e) {
developer.log('Network error', error: e, name: 'DataService');
return Result.failure('Connection failed. Please check your internet.');
} on ValidationException catch (e) {
developer.log('Validation error', error: e, name: 'DataService');
return Result.failure('Invalid data format.');
} catch (e, st) {
developer.log('Unexpected error', error: e, stackTrace: st, name: 'DataService');
return Result.failure('Something went wrong. Please try again.');
}
}
class MyService {
final AppLogger _logger = const AppLogger(defaultTag: 'MyService');
Future<void> performOperation() async {
try {
await riskyOperation();
_logger.info('Operation completed successfully');
} on SpecificException catch (e) {
_logger.error('Specific error occurred', error: e);
throw ServiceException('User-friendly message');
} catch (e, st) {
_logger.error('Unexpected error', error: e, stackTrace: st);
throw ServiceException('Something went wrong');
}
}
}
Future<void> _onLoadData(
LoadData event,
Emitter<MyState> emit,
) async {
emit(MyLoading());
try {
final data = await useCase.getData();
emit(MyLoaded(data));
} on NetworkException catch (e) {
emit(MyError('Connection failed. Please check your internet.'));
} catch (e, st) {
developer.log('Unexpected error', error: e, stackTrace: st, name: 'MyBloc');
emit(MyError('Something went wrong. Please try again.'));
}
}
For operations that can fail, consider Result pattern:
// Result pattern
sealed class Result<T> {
const Result();
}
class Success<T> extends Result<T> {
final T value;
const Success(this.value);
}
class Failure<T> extends Result<T> {
final String error;
const Failure(this.error);
}
// Usage
Future<Result<User>> getUser(String id) async {
try {
final user = await repository.getUser(id);
return Success(user);
} catch (e) {
return Failure('Failed to load user: ${e.toString()}');
}
}
Always show user-friendly messages:
// In widget
if (state is MyError) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(state.message), // User-friendly message
backgroundColor: AppColors.error,
),
);
}
❌ Silent Failure:
try {
await operation();
} catch (e) {
// Silent failure - BAD!
}
❌ Generic Catch Only:
try {
await operation();
} catch (e) {
// Missing specific exception handling - BAD!
}
❌ No Logging:
try {
await operation();
} catch (e) {
showError('Error'); // Missing error logging - BAD!
}
development
--- name: world-model-development description: Guides world model development patterns: state/action encoders, ONNX inference, feature extraction pipeline, latency budgets. Use when implementing world model components, state encoders, action encoders, feature extractors, or ONNX models. Core skill for Phases 3-6. --- # World Model Development Patterns ## Core Principle All world model components follow LeCun's autonomous machine intelligence framework. State observations flow through a percep
tools
Implements base workflow controller patterns for multi-step processes. Use when creating complex workflows that require orchestration of multiple steps with error handling and rollback.
testing
--- name: widget-test-patterns description: Guides widget test patterns: BLoC testing, user interactions, state changes, material app setup. Use when writing widget tests, testing UI components, or validating widget behavior. --- # Widget Test Patterns ## Core Pattern Widget tests verify UI behavior: user interactions, state changes, and visual display. ## Basic Widget Test Setup ```dart testWidgets('widget displays correctly', (WidgetTester tester) async { // Arrange: Create widget awa
testing
--- name: test-template-generation description: Generates test templates: unit, widget, integration, service tests following project patterns. Use when creating new tests or ensuring tests follow project standards. --- # Test Template Generation ## Available Templates Test templates are located in `test/templates/`: - `unit_test_template.dart` - `widget_test_template.dart` - `integration_test_template.dart` - `service_test_template.dart` ## Unit Test Template ```dart /// SPOTS Component Uni