Git Product home page Git Product logo

Comments (6)

rodinaarssen avatar rodinaarssen commented on June 26, 2024 1

After iprintln'ing an ast with lineLimit=-1, the following is appended for me instead of the cancelled:

Exception in thread "main" java.lang.NumberFormatException: For input string: "30m"
        at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
        at java.base/java.lang.Integer.parseInt(Integer.java:652)
        at java.base/java.lang.Integer.<init>(Integer.java:1105)
        at org.fusesource.jansi.AnsiOutputStream.write(AnsiOutputStream.java:122)
        at java.base/java.io.FilterOutputStream.write(FilterOutputStream.java:137)
        at java.base/sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:233)
        at java.base/sun.nio.cs.StreamEncoder.implWrite(StreamEncoder.java:303)
        at java.base/sun.nio.cs.StreamEncoder.implWrite(StreamEncoder.java:281)
        at java.base/sun.nio.cs.StreamEncoder.write(StreamEncoder.java:125)
        at java.base/sun.nio.cs.StreamEncoder.write(StreamEncoder.java:135)
        at java.base/java.io.OutputStreamWriter.write(OutputStreamWriter.java:226)
        at org.rascalmpl.repl.WrappedFilterWriter.write(WrappedFilterWriter.java:37)
        at java.base/java.io.PrintWriter.write(PrintWriter.java:542)
        at java.base/java.io.PrintWriter.write(PrintWriter.java:559)
        at java.base/java.io.PrintWriter.print(PrintWriter.java:686)
        at java.base/java.io.PrintWriter.println(PrintWriter.java:822)
        at org.rascalmpl.repl.BaseREPL.run(BaseREPL.java:367)
        at org.rascalmpl.vscode.lsp.terminal.LSPTerminalREPL.main(LSPTerminalREPL.java:345)
        Suppressed: java.lang.NumberFormatException: For input string: "30m
                t java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
                at java.base/java.lang.Integer.parseInt(Integer.java:652)
                at java.base/java.lang.Integer.<init>(Integer.java:1105)
                at org.fusesource.jansi.AnsiOutputStream.write(AnsiOutputStream.java:122)
                at java.base/java.io.FilterOutputStream.write(FilterOutputStream.java:137)
                at java.base/java.io.FilterOutputStream.write(FilterOutputStream.java:108)
                at org.fusesource.jansi.AnsiOutputStream.close(AnsiOutputStream.java:506)
                at java.base/sun.nio.cs.StreamEncoder.implClose(StreamEncoder.java:341)
                at java.base/sun.nio.cs.StreamEncoder.close(StreamEncoder.java:161)
                at java.base/java.io.OutputStreamWriter.close(OutputStreamWriter.java:255)
                at java.base/java.io.FilterWriter.close(FilterWriter.java:114)
                at java.base/java.io.PrintWriter.close(PrintWriter.java:415)
                at org.rascalmpl.repl.BaseREPL.run(BaseREPL.java:366)
                ... 1 more

Control is never returned, :quit does not work.

from rascal.

jurgenvinju avatar jurgenvinju commented on June 26, 2024

@DavyLandman is this a nice one for you?

from rascal.

jurgenvinju avatar jurgenvinju commented on June 26, 2024
  • This behavior is consistent for any value that is printed
  • Without lineLimit=-1 it works much better.

from rascal.

jurgenvinju avatar jurgenvinju commented on June 26, 2024

Looks like were stacking a number of issues here:

 try (PrintWriter err = new PrintWriter(errorWriter, true)) {
                err.println("Unexpected (uncaught) exception, closing the REPL: ");
                if (!err.checkError()) {
                    err.print(e.toString());
                    e.printStackTrace(err);
                }
                else {
                    System.err.print(e.toString());
                    e.printStackTrace();
                }
                err.flush();
            }
            errorWriter.flush();
            throw e;

This code closes the error stream accidentally due to the try block "auto-close" feature. Pretty sure that's not supposed to happen.

The error that happens is not always printed because of this.

The actual error is that an ANSI escape seems to be started, but not correctly finished, which makes the ANSI parser crash. There is an unexpected m in the input after 30.

from rascal.

DavyLandman avatar DavyLandman commented on June 26, 2024

Indeed, -1 should not be a valid argument. I think we should make sure that <=0 is an illegal argument.

I don't have the time to look at that remark about closing the stream @jurgenvinju is this something that is only hit in a certain edge case? or in case of every exception?

from rascal.

jurgenvinju avatar jurgenvinju commented on June 26, 2024

Indeed, -1 should not be a valid argument. I think we should make sure that <=0 is an illegal argument.

-1 is a valid documented argument to iprint and iprintln's lineLimit parameter. It certainly is not the cause of the issue; but it is triggering the issue.

public void iprint(IValue arg, IInteger lineLimit){
		StandardTextWriter w = new StandardTextWriter(true, 2);
		Writer output = out;
		if (lineLimit.signum() > 0) {
		    output = new LimitedLineWriter(output, lineLimit.longValue());
		}

So here we see that the writer is only wrapped if the lineLimit is positive.

The rest of the code goes as follows:

try {
		    w.write(arg, output);
		} 
	    catch (/*IOLimitReachedException*/ RuntimeException e) {
	        // ignore, it's what we wanted
	    }
		catch (IOException e) {
			RuntimeExceptionFactory.io(values.string("Could not print indented value"));
		}
		finally {
		    try {
		        output.flush();
		        output.close();
		    }
		    catch (IOException e) {
		    }
		}

I suspect that the LimitedLineWriter has an error:

  • it does not close the wrapped stream on close()
  • this hides the real problem which is that iprint always tries to close the stream
  • but you should not close either stderr or stdout, that breaks the REPL.
  • the unwrapped stream is properly cascading the close.
  • so the fix is probably to not close the stream anymore.
  • the question is: why did I write it like this and why has this not bothered anyone before?
  • none of the other print methods close the stream.

from rascal.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.