mirror of
https://github.com/fluencelabs/fluence-js.git
synced 2024-12-04 18:00:18 +00:00
Fix issue with avm logs not being displayed (#54)
This commit is contained in:
parent
2e016e9b7a
commit
67a1f91961
6
package-lock.json
generated
6
package-lock.json
generated
@ -435,9 +435,9 @@
|
||||
}
|
||||
},
|
||||
"@fluencelabs/avm": {
|
||||
"version": "0.9.12",
|
||||
"resolved": "https://registry.npmjs.org/@fluencelabs/avm/-/avm-0.9.12.tgz",
|
||||
"integrity": "sha512-NCRGJafLa1Zs98IIOIALrPUoOEjesITsB9of2/r+IDgGKunf0NjI2/tqU5pK+37ye/qro5W+FJsHyseDh7zSDQ==",
|
||||
"version": "0.10.2",
|
||||
"resolved": "https://registry.npmjs.org/@fluencelabs/avm/-/avm-0.10.2.tgz",
|
||||
"integrity": "sha512-8FlCx3eTY5Xq5PdE1Fa1rrjrw8oNIdNSnjAxl1MYKL4IEurtRmzQbvFa7s06uX8nU0CRh7UTf9B5xqGOHWGBpA==",
|
||||
"requires": {
|
||||
"base64-js": "1.5.1"
|
||||
},
|
||||
|
@ -19,7 +19,7 @@
|
||||
"author": "Fluence Labs",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@fluencelabs/avm": "0.9.12",
|
||||
"@fluencelabs/avm": "0.10.2",
|
||||
"async": "3.2.0",
|
||||
"base64-js": "1.3.1",
|
||||
"bs58": "4.0.1",
|
||||
|
@ -85,7 +85,7 @@ describe('Builtins usage suite', () => {
|
||||
let promise = createService(client, 'test_broken_blueprint');
|
||||
|
||||
await expect(promise).rejects.toMatchObject({
|
||||
error: expect.stringContaining("Blueprint 'test_broken_blueprint' wasn't found"),
|
||||
msg: expect.stringContaining("Blueprint 'test_broken_blueprint' wasn't found"),
|
||||
instruction: expect.stringContaining('blueprint_id'),
|
||||
});
|
||||
});
|
||||
|
@ -2,7 +2,6 @@ import { checkConnection, createClient, FluenceClient } from '../../FluenceClien
|
||||
import Multiaddr from 'multiaddr';
|
||||
import { nodes } from '../connection';
|
||||
import { RequestFlowBuilder } from '../../internal/RequestFlowBuilder';
|
||||
import { error } from 'loglevel';
|
||||
|
||||
let client: FluenceClient;
|
||||
|
||||
@ -203,7 +202,7 @@ describe('Typescript usage suite', () => {
|
||||
|
||||
// assert
|
||||
await expect(promise).rejects.toMatchObject({
|
||||
error: expect.stringContaining("Service with id 'incorrect' not found"),
|
||||
msg: expect.stringContaining("Service with id 'incorrect' not found"),
|
||||
instruction: expect.stringContaining('incorrect'),
|
||||
});
|
||||
});
|
||||
@ -241,7 +240,7 @@ describe('Typescript usage suite', () => {
|
||||
|
||||
// assert
|
||||
await expect(res).rejects.toMatchObject({
|
||||
error: "Local service error: ret_code is 1024, error message is '\"The handler did not set any result. Make sure you are calling the right peer and the handler has been registered. Original request data was: serviceId='peer' fnName='identify' args=''\"'",
|
||||
msg: "Local service error: ret_code is 1024, error message is '\"The handler did not set any result. Make sure you are calling the right peer and the handler has been registered. Original request data was: serviceId='peer' fnName='identify' args=''\"'",
|
||||
instruction: 'call %init_peer_id% ("peer" "identify") [] res',
|
||||
});
|
||||
});
|
||||
|
@ -46,7 +46,7 @@ describe('Legacy api suite', () => {
|
||||
});
|
||||
|
||||
await expect(promise).rejects.toMatchObject({
|
||||
error: expect.stringContaining("Service with id 'incorrect' not found"),
|
||||
msg: expect.stringContaining("Service with id 'incorrect' not found"),
|
||||
instruction: expect.stringContaining('incorrect'),
|
||||
});
|
||||
});
|
||||
@ -78,7 +78,7 @@ describe('Legacy api suite', () => {
|
||||
const promise = sendParticleAsFetch<[string]>(client, new Particle(script), 'fn', 'service');
|
||||
|
||||
await expect(promise).rejects.toMatchObject({
|
||||
error: expect.stringContaining("Service with id 'incorrect' not found"),
|
||||
msg: expect.stringContaining("Service with id 'incorrect' not found"),
|
||||
instruction: expect.stringContaining('incorrect'),
|
||||
});
|
||||
});
|
||||
|
@ -25,9 +25,60 @@ import { CallServiceHandler } from './CallServiceHandler';
|
||||
import { loadRelayFn, loadVariablesService } from './RequestFlowBuilder';
|
||||
import { logParticle, Particle } from './particle';
|
||||
import log from 'loglevel';
|
||||
import { AirInterpreter, ParticleHandler, SecurityTetraplet, CallServiceResult } from '@fluencelabs/avm';
|
||||
import {
|
||||
AirInterpreter,
|
||||
ParticleHandler,
|
||||
SecurityTetraplet,
|
||||
CallServiceResult,
|
||||
LogLevel as AvmLogLevel,
|
||||
} from '@fluencelabs/avm';
|
||||
import makeDefaultClientHandler from './defaultClientHandler';
|
||||
|
||||
const createClient = (handler, peerId): Promise<AirInterpreter> => {
|
||||
let logLevel: AvmLogLevel = 'off';
|
||||
switch (log.getLevel()) {
|
||||
case 0: // 'TRACE'
|
||||
logLevel = 'trace';
|
||||
break;
|
||||
case 1: // 'DEBUG'
|
||||
logLevel = 'debug';
|
||||
break;
|
||||
case 2: // 'INFO'
|
||||
logLevel = 'info';
|
||||
break;
|
||||
case 3: // 'WARN'
|
||||
logLevel = 'warn';
|
||||
break;
|
||||
case 4: // 'ERROR'
|
||||
logLevel = 'error';
|
||||
break;
|
||||
case 5: // 'SILENT'
|
||||
logLevel = 'off';
|
||||
break;
|
||||
}
|
||||
const logFn = (level: AvmLogLevel, msg: string) => {
|
||||
switch (level) {
|
||||
case 'error':
|
||||
log.error(msg);
|
||||
break;
|
||||
|
||||
case 'warn':
|
||||
log.warn(msg);
|
||||
break;
|
||||
|
||||
case 'info':
|
||||
log.info(msg);
|
||||
break;
|
||||
|
||||
case 'debug':
|
||||
case 'trace':
|
||||
log.log(msg);
|
||||
break;
|
||||
}
|
||||
};
|
||||
return AirInterpreter.create(handler, peerId, logLevel, logFn);
|
||||
};
|
||||
|
||||
export class ClientImpl implements FluenceClient {
|
||||
readonly selfPeerIdFull: PeerId;
|
||||
|
||||
@ -68,12 +119,7 @@ export class ClientImpl implements FluenceClient {
|
||||
}
|
||||
|
||||
async initAirInterpreter(): Promise<void> {
|
||||
this.interpreter = await AirInterpreter.create(
|
||||
this.interpreterCallback.bind(this),
|
||||
this.selfPeerId,
|
||||
'trace',
|
||||
log.log,
|
||||
);
|
||||
this.interpreter = await createClient(this.interpreterCallback.bind(this), this.selfPeerId);
|
||||
}
|
||||
|
||||
async connect(multiaddr: string | Multiaddr, options?: FluenceConnectionOptions): Promise<void> {
|
||||
|
@ -20,7 +20,7 @@ import Peer from 'libp2p';
|
||||
import { decode, encode } from 'it-length-prefixed';
|
||||
import pipe from 'it-pipe';
|
||||
import * as log from 'loglevel';
|
||||
import { parseParticle, Particle, toPayload } from './particle';
|
||||
import { logParticle, parseParticle, Particle, toPayload } from './particle';
|
||||
import { NOISE } from 'libp2p-noise';
|
||||
import PeerId from 'peer-id';
|
||||
import Multiaddr from 'multiaddr';
|
||||
@ -114,7 +114,7 @@ export class FluenceConnection {
|
||||
if (this.status === Status.Initializing) {
|
||||
await this.node.start();
|
||||
|
||||
log.trace(`dialing to the node with client's address: ` + this.node.peerId.toB58String());
|
||||
log.debug(`dialing to the node with client's address: ` + this.node.peerId.toB58String());
|
||||
|
||||
try {
|
||||
await this.node.dial(this.address);
|
||||
@ -127,15 +127,13 @@ export class FluenceConnection {
|
||||
}
|
||||
}
|
||||
|
||||
let _this = this;
|
||||
|
||||
this.node.handle([PROTOCOL_NAME], async ({ connection, stream }) => {
|
||||
pipe(stream.source, decode(), async function (source: AsyncIterable<string>) {
|
||||
pipe(stream.source, decode(), async (source: AsyncIterable<string>) => {
|
||||
for await (const msg of source) {
|
||||
try {
|
||||
let particle = parseParticle(msg);
|
||||
log.trace('Particle is received:', JSON.stringify(particle, undefined, 2));
|
||||
_this.handleParticle(particle);
|
||||
const particle = parseParticle(msg);
|
||||
logParticle(log.debug, 'Particle is received:', particle);
|
||||
this.handleParticle(particle);
|
||||
} catch (e) {
|
||||
log.error('error on handling a new incoming message: ' + e);
|
||||
}
|
||||
@ -165,7 +163,7 @@ export class FluenceConnection {
|
||||
|
||||
let action = toPayload(particle);
|
||||
let particleStr = JSON.stringify(action);
|
||||
log.debug('send particle: \n' + JSON.stringify(action, undefined, 2));
|
||||
logParticle(log.debug, 'send particle: \n', particle);
|
||||
|
||||
// create outgoing substream
|
||||
const conn = (await this.node.dialProtocol(this.address, PROTOCOL_NAME)) as {
|
||||
|
@ -195,15 +195,14 @@ export class RequestFlowBuilder {
|
||||
|
||||
this.configHandler((h, request) => {
|
||||
h.onEvent(xorHandleService, xorHandleFn, (args) => {
|
||||
let msg;
|
||||
try {
|
||||
msg = JSON.parse(args[0]);
|
||||
} catch (e) {
|
||||
msg = e;
|
||||
if (args[0] === undefined) {
|
||||
log.error(
|
||||
'Request flow error handler recieved unexpected argument, value of %last_error% is undefined',
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
request.raiseError(msg);
|
||||
request.raiseError(args[0]);
|
||||
} catch (e) {
|
||||
log.error('Error handling script executed with error', e);
|
||||
}
|
||||
|
@ -32,7 +32,9 @@ export interface Particle {
|
||||
}
|
||||
|
||||
export const logParticle = (fn: Function, message: string, particle: Particle) => {
|
||||
fn(message, particle);
|
||||
const toLog = { ...particle };
|
||||
delete toLog.data;
|
||||
fn(message, toLog);
|
||||
};
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user