Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Dependencies
node_modules/
jspm_packages/

# Build output
dist/
build/
lib/
out/

# Coverage reports
coverage/
.nyc_output/

# Cache
.eslintcache
*.tsbuildinfo

# Test files
**/__tests__/**
**/__mocks__/**
**/test/**

# Documentation
docs/
*.md

# Configuration files
*.config.js
*.config.ts
50 changes: 50 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Source
src/
tests/
examples/
specs/

# Development configs
.github/
.vscode/
.idea/
.eslintrc*
.prettierrc*
.babelrc*
tsconfig.json
jest.config.js
webpack.config.*

# Development files
*.test.ts
*.spec.ts
*.test.js
*.spec.js
__tests__/
__mocks__/

# Documentation
docs/
*.md
LICENSE

# Build artifacts
coverage/
.nyc_output/
*.tsbuildinfo
.eslintcache

# Git files
.git/
.gitignore

# CI/CD
.travis.yml
.gitlab-ci.yml
.github/workflows/

# Editor files
*.swp
*.swo
.DS_Store
Thumbs.db
24 changes: 24 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Dependencies
node_modules/
jspm_packages/

# Build output
dist/
build/
lib/
out/

# Coverage reports
coverage/

# Generated files
*.generated.*
*.min.*

# Package files
package-lock.json
yarn.lock
pnpm-lock.yaml

# Documentation
docs/
125 changes: 125 additions & 0 deletions docs/error-handling.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# Enhanced Error Handling System

The enhanced error handling system provides a robust way to handle and track errors in FDO SDK plugins. It includes features for error notification management, persistence, and customizable error UI rendering.

## Components

### CircularBuffer

A fixed-size circular buffer implementation for efficient notification storage:

```typescript
import { CircularBuffer } from './utils/CircularBuffer';

const buffer = new CircularBuffer<string>(100); // Stores last 100 items
buffer.push("new item"); // Adds item, removing oldest if full
const items = buffer.toArray(); // Get all items in order
```

### NotificationManager

A singleton manager for handling error notifications:

```typescript
import { NotificationManager } from './utils/NotificationManager';

const manager = NotificationManager.getInstance();
manager.addNotification("An error occurred", "error", { details: "..." });
const errors = manager.getNotificationsByType("error");
```

### Error Handler Decorator

A method decorator for automatic error handling:

```typescript
import { handleError } from './decorators/ErrorHandler';

class MyPlugin {
// Basic usage
@handleError()
async doSomething() {
// Method implementation
}

// With custom error UI
@handleError({
errorMessage: "Custom error message",
returnErrorUI: true,
errorUIRenderer: (error) => `<custom-error>${error.message}</custom-error>`,
showNotifications: true,
context: { pluginId: "my-plugin" }
})
render() {
// Render implementation
}
}
```

## Features

1. **Automatic Error Catching**: The `@handleError` decorator automatically catches and processes errors.
2. **Notification Management**: Errors are stored in a circular buffer to prevent memory leaks.
3. **VS Code Integration**: Errors can be displayed in VS Code's notification system.
4. **Custom Error UI**: Support for custom error UI rendering in plugin views.
5. **Context Support**: Additional context can be attached to error notifications.
6. **Error History**: Access to historical error information through NotificationManager.

## Configuration Options

The `@handleError` decorator accepts these configuration options:

- `errorMessage`: Custom error message to display
- `returnErrorUI`: Whether to return default error UI for render methods
- `errorUIRenderer`: Custom function for rendering error UI
- `showNotifications`: Whether to show VS Code notifications
- `context`: Additional context to include with errors

## Error Result Interface

Methods decorated with `@handleError` return results in this format:

```typescript
interface ErrorResult<T> {
success: boolean;
error?: string;
result?: T;
notificationId?: string;
}
```

## Best Practices

1. Always provide meaningful error messages
2. Use context to include relevant debugging information
3. Implement custom error UI for better user experience
4. Monitor error history for debugging
5. Clear old notifications when appropriate

## Example Usage

```typescript
class MyPlugin {
@handleError({
errorMessage: "Failed to process data",
context: { source: "data-processor" }
})
async processData(data: any) {
// Implementation
}

@handleError({
returnErrorUI: true,
errorUIRenderer: (error) => `
<div class="error-container">
<h3>Error Processing Data</h3>
<p>${error.message}</p>
${error.details ? `<pre>${JSON.stringify(error.details, null, 2)}</pre>` : ''}
</div>
`
})
render() {
// Render implementation
}
}
```
Loading