Various minor fixes

This commit is contained in:
Sosthene 2025-08-25 01:13:57 +02:00
parent 832fa171d8
commit 1664b4aa69
3 changed files with 27 additions and 12 deletions

View File

@ -342,6 +342,8 @@ export class RelayManager {
break;
case "Commit":
console.log(`📨 Commit response from relay ${relayId}`);
// If we receive a commit response, that's basically an error
console.error(`❌ Commit response from relay ${relayId}:`, message.error);
break;
case "Cipher":
console.log(`📨 Cipher response from relay ${relayId}`);

View File

@ -608,7 +608,8 @@ export class Service {
const result = wasm.create_update_message(process, stateId, this.membersList);
return result;
} catch (error) {
throw new Error(`Failed to create update message: ${error}`);
const errorMessage = error instanceof Error ? error.message : String(error || 'Unknown error');
throw new Error(errorMessage);
}
}
@ -625,7 +626,8 @@ export class Service {
const result = wasm.validate_state(process, stateId, this.membersList);
return result;
} catch (error) {
throw new Error(`Failed to validate state: ${error}`);
const errorMessage = error instanceof Error ? error.message : String(error || 'Unknown error');
throw new Error(errorMessage);
}
}

View File

@ -4,7 +4,6 @@ import { config } from './config';
import { Service } from './service';
import { ApiReturn, Process } from '../pkg/sdk_client';
import { EMPTY32BYTES } from './utils';
import { rust_zstd_wasm_shim_calloc } from '../pkg/sdk_client_bg.wasm';
interface ServerMessageEvent {
data: {
@ -65,7 +64,8 @@ class SimpleProcessHandlers {
res = await this.service.createPrdUpdate(processId, stateId);
await this.service.handleApiReturn(res);
} catch (e) {
throw new Error(e as string);
const errorMessage = e instanceof Error ? e.message : String(e || 'Unknown error');
throw new Error(errorMessage);
}
return {
@ -73,8 +73,10 @@ class SimpleProcessHandlers {
messageId: event.data.messageId
};
} catch (e) {
const errorMsg = `Failed to notify update for process: ${e}`;
throw new Error(errorMsg);
const errorMessage = e instanceof Error ? e.message : String(e || 'Unknown error');
// Remove redundant "Error:" prefix and simplify the message
const cleanMessage = errorMessage.replace(/^Error:\s*/, '');
throw new Error(cleanMessage);
}
}
@ -100,7 +102,8 @@ class SimpleProcessHandlers {
res = await this.service.approveChange(processId, stateId);
await this.service.handleApiReturn(res);
} catch (e) {
throw new Error(e as string);
const errorMessage = e instanceof Error ? e.message : String(e || 'Unknown error');
throw new Error(errorMessage);
}
return {
@ -109,8 +112,10 @@ class SimpleProcessHandlers {
messageId: event.data.messageId
};
} catch (e) {
const errorMsg = `Failed to validate process: ${e}`;
throw new Error(errorMsg);
const errorMessage = e instanceof Error ? e.message : String(e || 'Unknown error');
// Remove redundant "Error:" prefix and simplify the message
const cleanMessage = errorMessage.replace(/^Error:\s*/, '');
throw new Error(cleanMessage);
}
}
@ -288,7 +293,8 @@ class SimpleProcessHandlers {
throw new Error(`Unhandled message type: ${event.data.type}`);
}
} catch (error) {
return this.errorResponse(error as string, event.clientId, event.data.messageId);
const errorMessage = error instanceof Error ? error.message : String(error || 'Unknown error');
return this.errorResponse(errorMessage, event.clientId, event.data.messageId);
}
}
}
@ -372,7 +378,11 @@ export class Server {
console.log('🔑 Already paired with id:', service.getPairingProcessId());
}
// Relays are automatically initialized in Service constructor
// Get all processes from database
await service.getAllProcessesFromDb();
// Connect to relays
await service.connectToRelaysAndWaitForHandshake();
console.log(`✅ Simple server running on port ${this.wss.options.port}`);
console.log('📋 Supported operations: UPDATE_PROCESS, NOTIFY_UPDATE, VALIDATE_STATE');
@ -412,9 +422,10 @@ export class Server {
this.sendToClient(ws, response);
} catch (error) {
console.error(`❌ Error handling message from ${clientId}:`, error);
const errorMessage = error instanceof Error ? error.message : String(error || 'Unknown error');
this.sendToClient(ws, {
type: MessageType.ERROR,
error: `Server error: ${error instanceof Error ? error.message : String(error)}`,
error: `Server error: ${errorMessage}`,
messageId: JSON.parse(data.toString())?.messageId
});
}