jquery.terminal: Uncaught TypeError When Calling Bunch of ``echo`` in a Loop

Issue summary

I am just printing a bunch of strings line by line to the terminal using echo and got into this error every time:

null:10460  Uncaught TypeError: Cannot read properties of undefined (reading 'length')
    at null:10460:59
    at FormatBuffer.forEach (null:1976:17)
    at FormatBuffer.flush (null:1982:14)
    at ready (null:10414:32)
    at DelayQueue.add (null:256:17)
    at null:9364:23
    at jQuery.fn.init.flush (null:10395:17)
    at jQuery.fn.init.flush (null:11486:32)
    at null:10781:42
    at unpromise (null:1136:20)

It is pointing to this line number 10460 (line 10390 in the source code) => https://github.com/jcubic/jquery.terminal/blob/ef9b63834a9bc2679fae45fd7d308873304016c3/js/jquery.terminal.js#L10390

I don’t think I can re-produce this error. But you can check out the Gif below term-error

Noted: all the white colored string characters come from a serial COM port. The weird thing is this error ONLY occurs on the 18th index of the for loop. This error cause the terminal to stop receiving data from the echo method until I type clear in the terminal then everything works again.

I was hoping you can give me some ideas why is the snapshot was undefined at that point, so I can track down what causing this in my end.

Thanks,

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 24 (21 by maintainers)

Commits related to this issue

Most upvoted comments

I have a bunch of fixes and features on the devel branch. So I think that I can release now.

The issue is fixed, Please don’t close it. I keep it open until it’s released.

Hey man, this time has passed, I wonder if you have any new thoughts on this bug, unfortunately I encountered it. Fortunately, I modified your code above and reproduced the bug.

function formatRender(textColor, data, bold) {
    return bold ? `[[b;${textColor};]${data}]` : `[[;${textColor};]${data}]`;
  }
const term = $('body').terminal(() => {}, {
      greetings: '',
      name: 'fdsaf',
      outputLimit: 5,
      wrap: false,
      isSupportCopyImg: false,
      pasteImage: false,
});
term.set_prompt(formatRender('#404040', 'WB>', true));
const lines = "[97][116 13 13 10 13 10 79 75 13 10 13 13 10][97][116 116 13 13 10][67][111 109 109 97 110 100 32 110 111 116 32 102 111 117 110 100 33 13 10 13 10 69 82 82 79 82 13 10 13 13 10][97][116 105 13 13 10 77 117 108 116 105 84 101 99 104 32 120 68 111 116 13 10 70 105 114 109 119 97 114 101 32 58 32 52 46 49 46 53 45 100 101 98 117 103 45 109 98 101 100 54 48 56 48 48 13 10 76 105 98 114 97 114 121][32][32 58 32 52 46 49 46 51 45 100 101 98 117 103 45 109 98 101 100 54 48 56 48 48 13 10 77 84 83 45 76 111 114 97 32 58 32 52 46 49 46 51 45 100 101 98 117 103 45 109 98 101 100 54 48 56 48 48 13 10 13 10][79][75 13 10 13 13 10][97][116 43 100 105 63 13 13 10][48][48 45 56 48 45 48 48 45 48 48 45 48 48 45 102 102 45 102 102 45 102 102 13 10 13 10 79 75 13 10 13 13 10]".split('][').map(line => {
    line = line.replace(/[[\]]/g, '');
    return line.split(' ').map(str => {
        return String.fromCharCode(+str);
    }).join('');
}).forEach(line => {
    term.echo(line, { newline: false });
});

github('jcubic/jquery.terminal');

@KiddoV Nothing has changed and I still need to see a reproduction.

At present, it seems that it is affected by outputLimit, but if I configure this limit but it is less than the total number of rows that may be displayed, will it not work?

I would just try to write code that connect to COM and just use:

const output = [];

// save all lines here:
output.push(com_line);

console.log(output);

You will see what is the output and you will be able to reproduce the error for instance on CodePen.

The reason why it’s better than saving into a file, because you can have undefined values, that may be in the output. If all are text you can save them into a file, or just write or just embed the JSON into the demo.