Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
167 views
in Technique[技术] by (71.8m points)

Hyperledger node.js failed to parse null

can somebody help with error which appears on HL Composer? Error content: Error: SyntaxError: Failed to parse null: Unexpected token (377:39) Line 377 is: let exists = await accounts.exists(element.destinationAcc)

        
        let accounts = await getAssetRegistry(ns + '.Account');
        let transactions = await getAssetRegistry(ns + '.Transactions');

        let allTransactions = await query('pendingTransactions');
        let allAccounts = await accounts.getAll();
      
        if (allTransactions.length() > 0) {
            allTransactions.forEach(element => {
                if (element.status == 'PENDING') {
                    
                    let exists = await accounts.exists(element.destinationAcc);
                   
                    if (exists) {
                        
                        let destAcc = await allAccounts.find(element.destinationAcc);
                        
                    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This is a pretty standard mistake that javascript developers make and isn't related to hyperledger composer at all.

You are trying to perform an await within a method that hasn't been declared async. HOWEVER even if you do add the keyword async to the method that you have declared inside the forEach declaration it still won't work, due to the way forEach works.

So for you the solution is, don't use the forEach method of an array to try to run an anonymous function with an await in it. Use an alternative method to iterate the allTransactions array such as a for loop.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...