Fix import paths and remove organ metaphors
Some checks failed
DSS Project Analysis / dss-context-update (push) Has been cancelled
Some checks failed
DSS Project Analysis / dss-context-update (push) Has been cancelled
- Update all `from storage.` imports to `from dss.storage.` - Update `from config import config` to use `dss.settings` - Update `from auth.` imports to `from dss.auth.` - Update health check to use `dss.mcp.handler` - Fix SmartMerger import (merger.py not smart_merger.py) - Fix TranslationDictionary import path - Fix test assertion for networkx edges/links - Remove organ/body metaphors from: - API server health check - CLI status command and help text - Admin UI logger and error handler 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,147 +1,139 @@
|
||||
/**
|
||||
* DSS Error Handler - Immune System Antibodies
|
||||
* DSS Error Handler
|
||||
*
|
||||
* The DSS Component's immune system uses these antibodies to detect and report threats.
|
||||
* Converts technical errors into human-friendly, actionable treatment plans.
|
||||
* Converts technical errors into user-friendly, actionable messages.
|
||||
* Integrates with the messaging system for structured error reporting.
|
||||
*
|
||||
* Biological Framework: These error messages use component metaphors to make
|
||||
* issues intuitive. See docs/DSS_ORGANISM_GUIDE.md for the full framework.
|
||||
*
|
||||
* @module error-handler
|
||||
*/
|
||||
|
||||
import { notifyError, ErrorCode } from './messaging.js';
|
||||
|
||||
/**
|
||||
* Error message templates with component metaphors
|
||||
*
|
||||
* These messages use biological language from the DSS Component Framework.
|
||||
* Each error is framed as a symptom the immune system detected, with
|
||||
* a diagnosis and treatment plan.
|
||||
* Error message templates with user-friendly descriptions
|
||||
*/
|
||||
const errorMessages = {
|
||||
// Figma API Errors - Sensory System Issues
|
||||
// Figma API Errors
|
||||
figma_403: {
|
||||
title: '🛡️ IMMUNE ALERT: Sensory Input Blocked',
|
||||
message: 'The DSS sensory organs cannot perceive the Figma file. Your access credentials lack permission.',
|
||||
title: 'Access Denied',
|
||||
message: 'Cannot access the Figma file. Your access credentials lack permission.',
|
||||
actions: [
|
||||
'Verify your Figma authentication token in Settings (nervous system communication)',
|
||||
'Confirm you have access to this file in Figma (sensory perception)',
|
||||
'Check if the file still exists (component awareness)',
|
||||
'Verify your Figma authentication token in Settings',
|
||||
'Confirm you have access to this file in Figma',
|
||||
'Check if the file still exists',
|
||||
],
|
||||
code: ErrorCode.FIGMA_API_ERROR,
|
||||
},
|
||||
figma_404: {
|
||||
title: '🛡️ IMMUNE ALERT: Sensory Target Lost',
|
||||
message: 'The Figma file the DSS sensory organs were trying to perceive doesn\'t exist or is inaccessible.',
|
||||
title: 'File Not Found',
|
||||
message: 'The Figma file doesn\'t exist or is inaccessible.',
|
||||
actions: [
|
||||
'Double-check your Figma file key in Settings (sensory focus)',
|
||||
'Double-check your Figma file key in Settings',
|
||||
'Verify the file hasn\'t been deleted in Figma',
|
||||
'Confirm you have access to the file in Figma (sensory perception)',
|
||||
'Confirm you have access to the file in Figma',
|
||||
],
|
||||
code: ErrorCode.FIGMA_API_ERROR,
|
||||
},
|
||||
figma_401: {
|
||||
title: '🔌 NERVOUS SYSTEM ALERT: Authentication Expired',
|
||||
message: 'The DSS nervous system\'s authentication with Figma has failed. Your sensory input token is invalid or expired.',
|
||||
title: 'Authentication Failed',
|
||||
message: 'Figma authentication failed. Your access token is invalid or expired.',
|
||||
actions: [
|
||||
'Refresh your Figma authentication token in Settings (nervous system repair)',
|
||||
'Get a fresh token from figma.com/settings (Account → Personal Access Tokens)',
|
||||
'Refresh your Figma authentication token in Settings',
|
||||
'Get a fresh token from figma.com/settings (Account -> Personal Access Tokens)',
|
||||
'Ensure you copied the full token without truncation',
|
||||
],
|
||||
code: ErrorCode.FIGMA_CONNECTION_FAILED,
|
||||
},
|
||||
figma_429: {
|
||||
title: '⚡ METABOLISM ALERT: Sensory Overload',
|
||||
message: 'The DSS is sensing too quickly. Figma\'s rate limits have been triggered.',
|
||||
title: 'Rate Limit Exceeded',
|
||||
message: 'Too many requests. Figma\'s rate limits have been triggered.',
|
||||
actions: [
|
||||
'Let the component rest for 1-2 minutes before sensing again',
|
||||
'Reduce how frequently the sensory system extracts data',
|
||||
'Wait 1-2 minutes before trying again',
|
||||
'Reduce how frequently you extract data',
|
||||
],
|
||||
code: ErrorCode.FIGMA_API_ERROR,
|
||||
},
|
||||
figma_500: {
|
||||
title: '🔌 EXTERNAL SYSTEM ALERT: Figma Component Stressed',
|
||||
message: 'Figma\'s servers are experiencing stress. This is external to DSS.',
|
||||
title: 'Figma Server Error',
|
||||
message: 'Figma\'s servers are experiencing issues. This is external to DSS.',
|
||||
actions: [
|
||||
'Wait while the external component recovers',
|
||||
'Check Figma health: status.figma.com',
|
||||
'Wait and try again later',
|
||||
'Check Figma status: status.figma.com',
|
||||
],
|
||||
code: ErrorCode.FIGMA_API_ERROR,
|
||||
},
|
||||
figma_demo: {
|
||||
title: '🛡️ IMMUNE ALERT: Invalid Sensory Configuration',
|
||||
message: 'The sensory organs are configured to look at "demo" which doesn\'t exist in Figma.',
|
||||
title: 'Invalid Configuration',
|
||||
message: 'The Figma file key is configured to "demo" which doesn\'t exist in Figma.',
|
||||
actions: [
|
||||
'Update Settings with your real Figma file key (configure sensory input)',
|
||||
'Update Settings with your real Figma file key',
|
||||
'Find your file key in the Figma URL: figma.com/file/[FILE_KEY]/...',
|
||||
'Use the Figma file selector in Settings',
|
||||
],
|
||||
code: ErrorCode.FIGMA_INVALID_KEY,
|
||||
},
|
||||
|
||||
// API Connection Errors - Nervous System / Heart Issues
|
||||
// API Connection Errors
|
||||
api_network: {
|
||||
title: '❤️ CRITICAL: Heart Not Responding',
|
||||
message: 'The DSS nervous system cannot reach the heart (server). The component is not responding.',
|
||||
title: 'Server Not Responding',
|
||||
message: 'Cannot connect to the DSS server.',
|
||||
actions: [
|
||||
'Verify the heart is beating: curl http://localhost:3456/health',
|
||||
'Restart the heart: cd tools/api && python3 -m uvicorn server:app --port 3456',
|
||||
'Check your network connection to the component',
|
||||
'Verify the server is running: curl http://localhost:3456/health',
|
||||
'Restart the server: ./scripts/dss start',
|
||||
'Check your network connection',
|
||||
],
|
||||
code: ErrorCode.SYSTEM_NETWORK,
|
||||
},
|
||||
api_timeout: {
|
||||
title: '⚡ METABOLISM ALERT: Component Overloaded',
|
||||
message: 'The DSS component took too long to respond. The heart may be stressed or metabolism sluggish.',
|
||||
title: 'Request Timeout',
|
||||
message: 'The server took too long to respond.',
|
||||
actions: [
|
||||
'Let the component rest and try again shortly',
|
||||
'Check the heart\'s logs for signs of stress: tail -f /tmp/dss-demo.log',
|
||||
'Reduce metabolic load (try processing smaller batches)',
|
||||
'Try again in a few moments',
|
||||
'Check the server logs: ./scripts/dss logs',
|
||||
'Try processing smaller batches',
|
||||
],
|
||||
code: ErrorCode.API_TIMEOUT,
|
||||
},
|
||||
api_500: {
|
||||
title: '🧠 BRAIN ALERT: Critical Processing Error',
|
||||
message: 'The DSS brain encountered a fatal error while processing your request.',
|
||||
title: 'Server Error',
|
||||
message: 'The server encountered an error while processing your request.',
|
||||
actions: [
|
||||
'Examine the brain\'s thoughts in the logs: tail -f /tmp/dss-demo.log',
|
||||
'Retry the operation to see if it recovers',
|
||||
'Report the issue if the component keeps failing',
|
||||
'Check the server logs: ./scripts/dss logs',
|
||||
'Retry the operation',
|
||||
'Report the issue if it persists',
|
||||
],
|
||||
code: ErrorCode.API_SERVER_ERROR,
|
||||
},
|
||||
|
||||
// Validation Errors - Immune System / Genetics
|
||||
// Validation Errors
|
||||
validation_missing_field: {
|
||||
title: '🛡️ IMMUNE ALERT: DNA Incomplete',
|
||||
message: 'The genetic code (configuration) is missing essential information. The component cannot proceed.',
|
||||
title: 'Missing Required Field',
|
||||
message: 'The configuration is missing required information.',
|
||||
actions: [
|
||||
'Fill in all fields marked as required (complete the genetic code)',
|
||||
'Fill in all fields marked as required',
|
||||
'Ensure each input field contains valid information',
|
||||
],
|
||||
code: ErrorCode.VALIDATION_MISSING_FIELD,
|
||||
},
|
||||
validation_invalid_format: {
|
||||
title: '🛡️ IMMUNE ALERT: Genetic Mutation Detected',
|
||||
message: 'One or more genetic sequences (configuration values) have an invalid format.',
|
||||
title: 'Invalid Format',
|
||||
message: 'One or more configuration values have an invalid format.',
|
||||
actions: [
|
||||
'Verify URLs start with http:// or https:// (correct genetic sequence)',
|
||||
'Check email addresses follow standard format (valid genetic code)',
|
||||
'Ensure file keys contain only letters, numbers, and hyphens (genetic pattern match)',
|
||||
'Verify URLs start with http:// or https://',
|
||||
'Check email addresses follow standard format',
|
||||
'Ensure file keys contain only letters, numbers, and hyphens',
|
||||
],
|
||||
code: ErrorCode.VALIDATION_INVALID_FORMAT,
|
||||
},
|
||||
|
||||
// Generic fallback
|
||||
unknown: {
|
||||
title: '🧬 ORGANISM ALERT: Unexplained Symptom',
|
||||
message: 'The DSS component experienced an unexpected problem. The root cause is unclear.',
|
||||
title: 'Unexpected Error',
|
||||
message: 'An unexpected problem occurred.',
|
||||
actions: [
|
||||
'Try the operation again (component may self-heal)',
|
||||
'Refresh if the issue persists (restart vitals)',
|
||||
'Check browser console for clues about the component\'s condition',
|
||||
'Try the operation again',
|
||||
'Refresh the page if the issue persists',
|
||||
'Check browser console for details',
|
||||
],
|
||||
code: ErrorCode.SYSTEM_UNEXPECTED,
|
||||
},
|
||||
@@ -253,7 +245,7 @@ export function handleError(error, context = {}) {
|
||||
});
|
||||
|
||||
// Log full details to console for debugging
|
||||
console.group(`🔴 ${parsed.title}`);
|
||||
console.group(`[ERROR] ${parsed.title}`);
|
||||
console.log('Message:', parsed.message);
|
||||
if (parsed.actions) {
|
||||
console.log('Actions:', parsed.actions);
|
||||
@@ -281,23 +273,23 @@ export async function tryWithErrorHandling(fn, context = {}) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user-friendly HTTP status message using component metaphors
|
||||
* Get user-friendly HTTP status message
|
||||
* @param {number} status - HTTP status code
|
||||
* @returns {string} User-friendly message with biological context
|
||||
* @returns {string} User-friendly message
|
||||
*/
|
||||
export function getStatusMessage(status) {
|
||||
const messages = {
|
||||
400: '🛡️ Genetic Code Invalid - the DNA sequence doesn\'t compile',
|
||||
401: '🔐 Authentication Failed - the nervous system can\'t verify identity',
|
||||
403: '🚫 Access Forbidden - immune system rejected this component',
|
||||
404: '👻 Target Lost - sensory organs can\'t perceive the resource',
|
||||
429: '⚡ Metabolism Overloaded - component sensing too quickly',
|
||||
500: '🧠 Brain Error - critical neural processing failure',
|
||||
502: '💀 Component Unresponsive - the heart has stopped beating',
|
||||
503: '🏥 Component In Recovery - temporarily unable to metabolize requests',
|
||||
400: 'Bad Request - invalid input data',
|
||||
401: 'Authentication Failed - invalid credentials',
|
||||
403: 'Access Forbidden - permission denied',
|
||||
404: 'Not Found - resource doesn\'t exist',
|
||||
429: 'Rate Limited - too many requests',
|
||||
500: 'Server Error - internal processing failure',
|
||||
502: 'Bad Gateway - server not responding',
|
||||
503: 'Service Unavailable - temporarily unable to handle requests',
|
||||
};
|
||||
|
||||
return messages[status] || `🔴 Unknown Component State - HTTP ${status}`;
|
||||
return messages[status] || `Unknown Error - HTTP ${status}`;
|
||||
}
|
||||
|
||||
export default {
|
||||
|
||||
@@ -1,35 +1,28 @@
|
||||
/**
|
||||
* DSS Logger - Component Brain Consciousness System
|
||||
* DSS Logger - Structured Logging System
|
||||
*
|
||||
* The DSS brain uses this logger to become conscious of what's happening.
|
||||
* Log levels represent the component's level of awareness and concern.
|
||||
* Provides structured logging with categories and levels for the DSS admin UI.
|
||||
*
|
||||
* Framework: DSS Component Framework
|
||||
* See: docs/DSS_ORGANISM_GUIDE.md#brain
|
||||
*
|
||||
* Log Categories (Organ Systems):
|
||||
* 'heart' - ❤️ Database operations and data persistence
|
||||
* 'brain' - 🧠 Validation, analysis, and decision making
|
||||
* 'nervous' - 🔌 API calls, webhooks, communication
|
||||
* 'digestive' - 🍽️ Data ingestion, parsing, transformation
|
||||
* 'circulatory' - 🩸 Design token flow and distribution
|
||||
* 'metabolic' - ⚡ Style-dictionary transformations
|
||||
* 'endocrine' - 🎛️ Theme system and configuration
|
||||
* 'immune' - 🛡️ Validation, error detection, security
|
||||
* 'sensory' - 👁️ Asset loading, Figma perception
|
||||
* 'skin' - 🎨 UI rendering, Storybook output
|
||||
* 'skeleton' - 🦴 Schema and structure validation
|
||||
*
|
||||
* Provides structured logging with biological awareness levels and optional remote logging.
|
||||
* Log Categories:
|
||||
* 'storage' - Database operations and data persistence
|
||||
* 'validation' - Validation, analysis, and decision making
|
||||
* 'api' - API calls, webhooks, communication
|
||||
* 'parser' - Data ingestion, parsing, transformation
|
||||
* 'tokens' - Design token flow and distribution
|
||||
* 'transform' - Style-dictionary transformations
|
||||
* 'config' - Theme system and configuration
|
||||
* 'security' - Validation, error detection, security
|
||||
* 'assets' - Asset loading, Figma integration
|
||||
* 'ui' - UI rendering, Storybook output
|
||||
* 'schema' - Schema and structure validation
|
||||
*/
|
||||
|
||||
// Component awareness levels - how conscious is the system?
|
||||
const LOG_LEVELS = {
|
||||
DEBUG: 0, // 🧠 Deep thought - brain analyzing internal processes
|
||||
INFO: 1, // 💭 Awareness - component knows what's happening
|
||||
WARN: 2, // ⚠️ Symptom - component detected something unusual
|
||||
ERROR: 3, // 🛡️ Immune alert - component detected a threat
|
||||
NONE: 4 // 🌙 Sleep - component is silent
|
||||
DEBUG: 0,
|
||||
INFO: 1,
|
||||
WARN: 2,
|
||||
ERROR: 3,
|
||||
NONE: 4
|
||||
};
|
||||
|
||||
class Logger {
|
||||
@@ -76,23 +69,22 @@ class Logger {
|
||||
this.logs.shift();
|
||||
}
|
||||
|
||||
// Console output with component awareness emojis
|
||||
const levelEmojis = {
|
||||
DEBUG: '🧠', // Brain thinking deeply
|
||||
INFO: '💭', // Component aware
|
||||
WARN: '⚠️', // Symptom detected
|
||||
ERROR: '🛡️' // Immune alert - threat detected
|
||||
const levelIcons = {
|
||||
DEBUG: '[D]',
|
||||
INFO: '[I]',
|
||||
WARN: '[W]',
|
||||
ERROR: '[E]'
|
||||
};
|
||||
|
||||
const colors = {
|
||||
DEBUG: 'color: #666; font-style: italic', // Gray, thoughtful
|
||||
INFO: 'color: #2196F3; font-weight: bold', // Blue, informative
|
||||
WARN: 'color: #FF9800; font-weight: bold', // Orange, warning
|
||||
ERROR: 'color: #F44336; font-weight: bold' // Red, critical
|
||||
DEBUG: 'color: #666; font-style: italic',
|
||||
INFO: 'color: #2196F3; font-weight: bold',
|
||||
WARN: 'color: #FF9800; font-weight: bold',
|
||||
ERROR: 'color: #F44336; font-weight: bold'
|
||||
};
|
||||
|
||||
const emoji = levelEmojis[level] || '🔘';
|
||||
const prefix = `${emoji} [${category}]`;
|
||||
const icon = levelIcons[level] || '[?]';
|
||||
const prefix = `${icon} [${category}]`;
|
||||
const style = colors[level] || '';
|
||||
|
||||
if (data) {
|
||||
@@ -120,56 +112,49 @@ class Logger {
|
||||
}
|
||||
|
||||
/**
|
||||
* 🧠 DEBUG - Brain's deep thoughts
|
||||
* Internal analysis and detailed consciousness
|
||||
* DEBUG - Detailed internal information
|
||||
*/
|
||||
debug(category, message, data) {
|
||||
this._log('DEBUG', category, message, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 💭 INFO - Component awareness
|
||||
* The system knows what's happening, stays informed
|
||||
* INFO - General information
|
||||
*/
|
||||
info(category, message, data) {
|
||||
this._log('INFO', category, message, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* ⚠️ WARN - Symptom detection
|
||||
* Component detected something unusual but not critical
|
||||
* WARN - Warning, something unusual detected
|
||||
*/
|
||||
warn(category, message, data) {
|
||||
this._log('WARN', category, message, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 🛡️ ERROR - Immune alert
|
||||
* Component detected a threat - critical consciousness
|
||||
* ERROR - Error, something went wrong
|
||||
*/
|
||||
error(category, message, data) {
|
||||
this._log('ERROR', category, message, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 📜 Get recent consciousness records
|
||||
* Retrieve the component's recent thoughts and awareness
|
||||
* Get recent log entries
|
||||
*/
|
||||
getRecentLogs(count = 50) {
|
||||
return this.logs.slice(-count);
|
||||
}
|
||||
|
||||
/**
|
||||
* 🧠 Clear the mind
|
||||
* Erase recent consciousness logs
|
||||
* Clear all logs
|
||||
*/
|
||||
clear() {
|
||||
this.logs = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 📤 Export consciousness
|
||||
* Save the component's awareness to a file for analysis
|
||||
* Export logs to file
|
||||
*/
|
||||
export() {
|
||||
const dataStr = JSON.stringify(this.logs, null, 2);
|
||||
@@ -185,13 +170,11 @@ class Logger {
|
||||
}
|
||||
|
||||
/**
|
||||
* 🧠 ORGANISM CONSCIOUSNESS
|
||||
* Create the DSS component's brain - a singleton logger that tracks all awareness
|
||||
* DSS Logger singleton
|
||||
*/
|
||||
const logger = new Logger('DSS', 'INFO');
|
||||
|
||||
// Set log level from localStorage or URL param
|
||||
// Allow tuning the component's consciousness level (awareness sensitivity)
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const logLevel = urlParams.get('log') || localStorage.getItem('dss_log_level') || 'INFO';
|
||||
logger.setLevel(logLevel.toUpperCase());
|
||||
|
||||
Reference in New Issue
Block a user