Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError: Cannot set property '0' of undefined #164

Closed
tqlihuiqi opened this issue Jul 6, 2016 · 15 comments
Closed

Uncaught TypeError: Cannot set property '0' of undefined #164

tqlihuiqi opened this issue Jul 6, 2016 · 15 comments

Comments

@tqlihuiqi
Copy link

execute vi / vim command throw exception

error:
Uncaught TypeError: Cannot set property '0' of undefined

debug:
Serial port requested application keypad.

code:
<script src="/static/plugins/xterm/src/xterm.js"></script>

    var currentWs = new ReconnectingWebSocket('ws://{{ wsServer }}/ws/terminal/current');
    currentWs.onopen =  function(event) {
        var xterm = new Terminal({
            geometry: [98, 26],
            debug: true
        });
        xterm.open(document.getElementById('currentRecord'));
        currentWs.onmessage = function(event) {
            xterm.write(event.data);
        }; 
    }
@akalipetis
Copy link
Contributor

Hello @tqlihuiqi - thanks for reporting.

Are you testing on the latest master branch? Also, in which browser you're testing?
I just tried running vi/vim on the Xterm demo but could not reproduce this on Chrome/Firefox on OSX.

@tqlihuiqi
Copy link
Author

Hi, @akalipetis

I use the latest master branch on Chrome/Firefox on OSX.

I've already resolve this issue.

code:

var currentWs = new ReconnectingWebSocket('ws://{{ wsServer }}/ws/terminal/current');
currentWs.onopen =  function(event) {
    var xterm = new Terminal({
        geometry: [98, 26],
        debug: true
    });
    xterm.open(document.getElementById('currentRecord'));
    currentWs.onmessage = function(event) {
        if(!xterm.write(event.data)){
            xterm.write('');
        }
    }; 
}

@jerch
Copy link
Member

jerch commented Jul 7, 2016

@tqlihuiqi Could you provide more info about what you did, the error (with stacktrace?) and what exactly fixed the problem? The

        if(!xterm.write(event.data)){
            xterm.write('');
        }

doesnt look like a real solution to me - you still execute xterm.write(event.data) and evaluate a nonexistent return value (the if condition will always be true).

Atm your description is somewhat cryptic and not reproducable with the spare info.

@tqlihuiqi
Copy link
Author

@jerch

I have written a with the function of audit SSH client,I want to send the output file via a browser display, So I use the WEBSOCKET receives the message, and then through the XTERM to display a message to the page. At that time when I was in terminal input VI command, raised exception.

I try to write VI command returns a message on the console:

console.log(event.data)

terminal:524 v
terminal:524 i
terminal:524 

terminal:524 �[?1h�=
terminal:524 �[1;30r�[m�[m�[0m�[H�[J�[2;1H�[1m~

25terminal:524 ~

XTERM throw an exception

Terminal.write  @   xterm.js:1603
currentWs.onmessage @   terminal:525
(anonymous function)    @   reconnecting-websocket.js:182
ws.onmessage    @   reconnecting-websocket.js:282

xterm.js:1603
this.lines[this.y + this.ybase][this.x] = [this.curAttr, ch, ch_width];

So I judge xterm.write(event.data) back to write page success, throw an exception when I would write a null character

@jerch
Copy link
Member

jerch commented Jul 8, 2016

Looks like this.lines or this.lines[this.y + this.ybase] is undefined. You'd have to inspect both to see what is wrong here, either with printf-debugging (console.log) or with a breakpoint at xterm.js:1603.

I guess your xterm geometry is not in sync with the pty, since vi is trying to set the y scroll margins to 0 and 29 ([1;30r in your second vi output line).

@parisk
Copy link
Contributor

parisk commented Jul 13, 2016

@tqlihuiqi opening vim in the demo page does not throw any errors or exceptions. When I explicitly write the NUL byte character to the terminal with term.write('\0') still no error or exception is being raised.

Could you please update to the latest version of the master branch and provide us with the following information:

  1. On what OS does the back-end PTY of your xterm.js instance run?
  2. What is the exact command that you run
  3. A screenshot of your app with the Chrome DevTools open in the Console tab

This way we will be able to approach this problem better and find out why this happens.

@JasinYip
Copy link

JasinYip commented Aug 19, 2016

I have the same problem on our project. Opening vim does not throw any errors before I press some keys like j.

And I could use :q to exit vim but after that, the last line of the terminal will change its color to purple. That's really weird...

@LucianBuzzo
Copy link
Contributor

LucianBuzzo commented Jan 27, 2017

I've been able to replicate this issue by setting a scroll region to a bottom value that is higher then the number of rows, then printing a lot of new lines to the screen.
You can do this using the following simple bash script:

printf "\033[1;300r"
grep -Rl ' ' .

I'll submit a PR with a fix.

parisk added a commit that referenced this issue Jan 27, 2017
[issue #164] Fix bug that can occur when setting a scroll region
@parisk
Copy link
Contributor

parisk commented Jan 27, 2017

Closed in #514.

@parisk parisk closed this as completed Jan 27, 2017
@tht13
Copy link

tht13 commented May 11, 2017

I am on the latest version of xterm and am receiving this error again. Has something gone in recently which could have brought this bug back? It always seems to fail on row 24. While my terminal is configured with 7 rows. I inspected the this._terminal.lines element and there are only 23 rows but "24.2" does exist.

@Tyriar
Copy link
Member

Tyriar commented May 11, 2017

@tht13 can you get the stack and try find the line it's failing on? I added some defensive checks to protect against at least one case of this. It might be a different regression (I haven't seen any reports though on 2.6).

@tht13
Copy link

tht13 commented May 12, 2017

It is failing on InputHandler.ts:86

Stacktrace:

InputHandler.ts:86 Uncaught TypeError: Cannot set property '0' of undefined
    at InputHandler.addChar (InputHandler.ts:86)
    at Parser.parse (Parser.ts:221)
    at Terminal.innerWrite (xterm.js:1296)
    at xterm.js:1275
InputHandler.addChar @ InputHandler.ts:86
Parser.parse @ Parser.ts:221
Terminal.innerWrite @ xterm.js:1296
(anonymous) @ xterm.js:1275
setTimeout (async)
Terminal.write @ xterm.js:1274
log @ terminal.tsx:25

@tht13
Copy link

tht13 commented May 12, 2017

I've debugged a bit further and the problem seems to come from calling a resize while writing to the terminal. The async nature of the write seems to cause some issue. I'll add a wait on the resize event to my code, that should fix it.

@tht13
Copy link

tht13 commented May 12, 2017

Unfortunately waiting on the resize event didn't help, I thought I solved the issue by delaying the resize through a timeout but it seems that any write to the terminal after the resize causes it to fail, even if it is minute later.

Here is some code which should reproduce the issue (without the timeout):

const term = new xterm();
term.open(document.getElementById("container"));
term.resize(cols, rows);
for (let i=0;i<30;i++) term.writeln(i.toString());

@Tyriar
Copy link
Member

Tyriar commented May 12, 2017

Thanks @tht13, I created #661 to follow this up, hopefully in the next version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants