even more logs!

This commit is contained in:
MaxRobinsonTheGreat 2024-11-07 10:48:45 -06:00
parent fd096b5ae3
commit 5fb52e6d73
3 changed files with 49 additions and 19 deletions

View file

@ -15,29 +15,46 @@ import settings from '../../settings.js';
export class Agent { export class Agent {
async start(profile_fp, load_mem=false, init_message=null, count_id=0) { async start(profile_fp, load_mem=false, init_message=null, count_id=0) {
try { try {
// Initialize components with error handling // Add validation for profile_fp
this.actions = new ActionManager(this); if (!profile_fp) {
this.prompter = new Prompter(this, profile_fp); throw new Error('No profile filepath provided');
this.name = this.prompter.getName(); }
this.history = new History(this);
this.coder = new Coder(this); console.log('Starting agent initialization with profile:', profile_fp);
this.npc = new NPCContoller(this);
this.memory_bank = new MemoryBank(); // Initialize components with more detailed error handling
this.self_prompter = new SelfPrompter(this); try {
console.log('Initializing action manager...');
this.actions = new ActionManager(this);
console.log('Initializing prompter...');
this.prompter = new Prompter(this, profile_fp);
this.name = this.prompter.getName();
console.log('Initializing history...');
this.history = new History(this);
console.log('Initializing coder...');
this.coder = new Coder(this);
console.log('Initializing npc controller...');
this.npc = new NPCContoller(this);
console.log('Initializing memory bank...');
this.memory_bank = new MemoryBank();
console.log('Initializing self prompter...');
this.self_prompter = new SelfPrompter(this);
} catch (error) {
throw new Error(`Failed to initialize agent components: ${error.message || error}`);
}
try { try {
console.log('Initializing examples...');
await this.prompter.initExamples(); await this.prompter.initExamples();
} catch (error) { } catch (error) {
console.error('Failed to initialize examples:', error); throw new Error(`Failed to initialize examples: ${error.message || error}`);
throw error;
} }
console.log('Logging into minecraft...'); console.log('Logging into minecraft...');
try { try {
this.bot = initBot(this.name); this.bot = initBot(this.name);
} catch (error) { } catch (error) {
console.error('Failed to initialize Minecraft bot:', error); throw new Error(`Failed to initialize Minecraft bot: ${error.message || error}`);
throw error;
} }
initModes(this); initModes(this);
@ -89,8 +106,13 @@ export class Agent {
}); });
}); });
} catch (error) { } catch (error) {
console.error('Failed to start agent:', error); // Ensure we're not losing error details
throw error; // Re-throw to be caught by init-agent.js console.error('Agent start failed with error:', {
message: error.message || 'No error message',
stack: error.stack || 'No stack trace',
error: error
});
throw error; // Re-throw with preserved details
} }
} }

View file

@ -40,7 +40,7 @@ export class AgentProcess {
}); });
agentProcess.on('error', (err) => { agentProcess.on('error', (err) => {
console.error('Failed to start agent process:', err); console.error('Agent process error:', err);
}); });
} }
} }

View file

@ -3,8 +3,11 @@ import yargs from 'yargs';
// Add global unhandled rejection handler // Add global unhandled rejection handler
process.on('unhandledRejection', (reason, promise) => { process.on('unhandledRejection', (reason, promise) => {
console.error('Unhandled Rejection at:', promise); console.error('Unhandled Rejection at:', {
console.error('Reason:', reason); promise: promise,
reason: reason,
stack: reason?.stack || 'No stack trace'
});
process.exit(1); process.exit(1);
}); });
@ -40,10 +43,15 @@ const argv = yargs(args)
// Wrap agent start in async IIFE with proper error handling // Wrap agent start in async IIFE with proper error handling
(async () => { (async () => {
try { try {
console.log('Starting agent with profile:', argv.profile);
const agent = new Agent(); const agent = new Agent();
await agent.start(argv.profile, argv.load_memory, argv.init_message, argv.count_id); await agent.start(argv.profile, argv.load_memory, argv.init_message, argv.count_id);
} catch (error) { } catch (error) {
console.error('Failed to start agent:', error); console.error('Failed to start agent process:', {
message: error.message || 'No error message',
stack: error.stack || 'No stack trace',
error: error
});
process.exit(1); process.exit(1);
} }
})(); })();