Skip to content
Merged
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
19 changes: 13 additions & 6 deletions src/instance/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export class InstanceManager {
throw new Error(`Instance '${name}' is not running`);
}

if (config.status.pid) {
if (config.status?.pid) {
// Stop PostgreSQL process gracefully
await this.stopPostgreSQLProcess(config.status.pid);
}
Expand Down Expand Up @@ -164,9 +164,9 @@ export class InstanceManager {
// Check if process is actually running
if (config.status?.pid) {
const isRunning = await this.isProcessRunning(config.status.pid);
if (!isRunning && config.status.state === 'running') {
if (!isRunning && config.status?.state === 'running') {
// Process died, update status
config.status.state = 'stopped';
config.status!.state = 'stopped';
await this.configManager.saveInstanceConfig(config);
}
}
Expand Down Expand Up @@ -324,9 +324,12 @@ export class InstanceManager {
try {
console.log(`Executing: ${command.replace(/PASSWORD '[^']*'/g, "PASSWORD '[REDACTED]'")}`);
const result = await execAsync(command, options);
return result;
return {
stdout: result.stdout.toString(),
stderr: result.stderr.toString()
};
} catch (error) {
const errorMsg = error instanceof Error ? error.message : String(error);
const errorMsg = error instanceof Error ? (error.message || 'Unknown error') : String(error);
console.error(`Command failed: ${command.replace(/PASSWORD '[^']*'/g, "PASSWORD '[REDACTED]'")}`);
console.error(`Error: ${errorMsg}`);
throw error;
Expand All @@ -341,7 +344,11 @@ export class InstanceManager {
const bytes = randomBytes(length);

for (let i = 0; i < length; i++) {
password += characters[bytes[i] % characters.length];
const byte = bytes[i];
if (byte === undefined) {
throw new Error('Failed to generate secure random bytes');
}
password += characters[byte % characters.length];
}

return password;
Expand Down