thread '' panicked at 'called Option :: unwrap () on a None value' in console

0

Could someone tell me how to solve the following error?

thread '<unnamed>' panicked at 'called 'Option::unwrap()' on a 'None' value', /checkout/src/libcore/option.rs:335:20
note: Run with 'RUST_BACKTRACE=1' for a backtrace.
failed to parse:  5275944
undefined
TypeError: Cannot read property 'messages' of undefined
    at fetchStartCount.then.v (C:\...\publishPublicStart.js:46:24)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

The point is that the first time I launch it works without problems. The 2nd and third seems that, too, the code is added to the Tangle network, but suddenly to a random number of executions that error jumps me and I can not continue writing anything in the blockchain. It is a javascript to write strings in an IOTA network.

The point is that I tried to install the RUST and set the variable to 'RUST_BACKTRACE = 1' but I'm still there. On the other hand, he tells me that he can not read 'messages' of undefined, but since it's just a test network, I'm sending him the same string all the time so it does not make sense, or at least I do not see it, that the first N times I send it to work and then tell me it is undefined.

My code is as follows:

// Replace this with absolute path to your mam.node.js
var Mam = require('C:/...Mi ruta.../mam.node.js')
let IOTA = require('iota.lib.js');
var iota = new IOTA({ provider: 'http://173.249.43.8:14265' })
var now = Date.now()
let yourMessage = "Codigo: 202";

// Please supply a SEED --> 81 chars of A-Z9 //
let seed = 'M9IOADJXXRTRHOVPMXZDD9XSRWOBPZAKHPHNPWI99PAOJFZFCSUUIYLFKNWOQTWKJUJFRXBRNEBAGXCID';
// Length: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

let mamState = null;

async function fetchStartCount() {
    let trytes = iota.utils.toTrytes('START');
    let message = Mam.create(mamState, trytes);
    console.log('The first root:');
    console.log(message.root);
    console.log();
    // Fetch all the messages upward from the first root.
    return await Mam.fetch(message.root, 'public', null, null);
}

async function publish(packet) {
    // Create the message.
    let trytes = iota.utils.toTrytes(JSON.stringify(packet))
    let message = Mam.create(mamState, trytes);
    // Set the mam state so we can keep adding messages.
    mamState = message.state;
    console.log('Sending message: ', packet);
    console.log('Root: ', message.root);
    console.log('Address: ', message.address);
    console.log();
    // Attach the message.
    return await Mam.attach(message.payload, message.address);
}

// Initiate the mam state with the given seed at index 0.
mamState = Mam.init(iota, seed, 2, 0);

// Fetch all the messages in the stream.
fetchStartCount().then(v => {
    // Log the messages.
    var prueba = v;
    console.log(prueba);
    let startCount = v.messages.length;
    console.log('Messages already in the stream:');
    for (let i = 0; i < v.messages.length; i++) {
        let msg = v.messages[i];
        console.log(JSON.parse(iota.utils.fromTrytes(msg)));
    }
    console.log();

    // To add messages at the end we need to set the startCount for the mam state to the current amount of messages.
    mamState = Mam.init(iota, seed, 2, startCount);

    let newMessage = Date.now() + ' ' + yourMessage;

    // Now the mam state is set, we can add the message.
    publish(newMessage);
}).catch(ex => {
    console.log(ex);
});

Thank you very much !!

    
asked by Jonan87 18.09.2018 в 09:46
source

0 answers