awjh-ibm / vehicle-manufacture-iot-extension

Apache License 2.0
0 stars 2 forks source link

Cannot read property 'split' of undefined #33

Open jtyoui opened 3 years ago

jtyoui commented 3 years ago

Hello author: This is program appear fatal error that I run.

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   857  100   669  100   188   5868   1649 --:--:-- --:--:-- --:--:--  7517
Error handling transaction. ERROR: No valid responses from any peers. 3 peer error responses:
    peer=peer0.arium.com, status=500, message=transaction returned with failure: Error: Unable to load participant for client registrar@VDA ERROR: Cannot read property 'split' of undefined
    peer=peer0.vda.com, status=500, message=transaction returned with failure: Error: Unable to load participant for client registrar@VDA ERROR: Cannot read property 'split' of undefined
    peer=peer0.prince-insurance.com, status=500, message=transaction returned with failure: Error: Unable to load participant for client registrar@VDA ERROR: Cannot read property 'split' of undefinedREGISTERING USER audit
jtyoui commented 3 years ago

Hello author:
I find that I run program appear fatal errro,Beacuse project src file have a bug that sourece src/lib/ledger-api/state.ts

 public async loadParticipant(): Promise<{ participant: Participant, organization: Organization }> {
        const id = this.getAttributeValue(ID_FIELD);
        try {
            logger.info(`print  id=${id}`);
            const participant = await this.ctx.getParticipantList().get(id);
            logger.info(`print participant=${participant}`);
            logger.info(`print participant.orgId=${participant.orgId}`);
            return {
                organization: await this.ctx.getOrganizationList().get(participant.orgId),
                participant,
            };
        } catch (err) {
            throw new Error(`Unable to load participant for client ${id} ERROR: ${err.message}`);
        }
    }

I print participant.orgId===undefined. I find function this.ctx.getOrganizationList().get to address src/lib/ledger-api/statelist.ts

public async get(key: string): Promise<T> {
        const ledgerKey = this.ctx.stub.createCompositeKey(this.name, State.splitKey(key));
        const data = await this.ctx.stub.getState(ledgerKey);

        if (data.length === 0) {
            throw new Error(`Cannot get state. No state exists for key ${key} ${this.name}`);
        }
        const state = State.deserialize(data, this.supportedClasses) as T;

        return state;
    }

I find State.splitKey(key) appear error! beacuse key===undefined.

public static splitKey(key: string | undefined): string[] {
        logger.info(`print :key=${key}`);
        if (key) {
            return key.split(':');
        }
        return [];
    }
iceriverdog commented 3 years ago

Hello author: I find that I run program appear fatal errro,Beacuse project src file have a bug that sourece src/lib/ledger-api/state.ts

 public async loadParticipant(): Promise<{ participant: Participant, organization: Organization }> {
        const id = this.getAttributeValue(ID_FIELD);
        try {
            logger.info(`print  id=${id}`);
            const participant = await this.ctx.getParticipantList().get(id);
            logger.info(`print participant=${participant}`);
            logger.info(`print participant.orgId=${participant.orgId}`);
            return {
                organization: await this.ctx.getOrganizationList().get(participant.orgId),
                participant,
            };
        } catch (err) {
            throw new Error(`Unable to load participant for client ${id} ERROR: ${err.message}`);
        }
    }

I print participant.orgId===undefined. I find function this.ctx.getOrganizationList().get to address src/lib/ledger-api/statelist.ts

public async get(key: string): Promise<T> {
        const ledgerKey = this.ctx.stub.createCompositeKey(this.name, State.splitKey(key));
        const data = await this.ctx.stub.getState(ledgerKey);

        if (data.length === 0) {
            throw new Error(`Cannot get state. No state exists for key ${key} ${this.name}`);
        }
        const state = State.deserialize(data, this.supportedClasses) as T;

        return state;
    }

I find State.splitKey(key) appear error! beacuse key===undefined.

public static splitKey(key: string | undefined): string[] {
        logger.info(`print :key=${key}`);
        if (key) {
            return key.split(':');
        }
        return [];
    }

Great bro!Do you know how to solve this BUG?Any help from you will be greatly appreciated!!