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

Allow the console to contain "Error" (or even a backtrace) on startup #88

Open
Hardtack opened this issue May 17, 2016 · 3 comments
Open

Comments

@Hardtack
Copy link

Robe checks the initialization of subprocess with text of subprocess' stdout. It checks the existence of word that ends with "Error". But some projects print initial message (before the robe starts), they can print the word "Error" to the stdout.

For example,

WARNING: Some ignorable error occurred during initialization.
#<SomeError cannot load optional module 'liboptional.so'>
... [stack trace]

[1] pry(main)> => "robe on 12345"

In this case, the robe was started normally in ruby process, but emacs-side's robe thinks that it was not started well.

Using external file like .robe-port would be possible solution

@dgutov
Copy link
Owner

dgutov commented May 17, 2016

Hi! Thanks for the report, but I'd expect fixing this will require some major changes. We're looking for the string Error\\> in the loop that waits until Robe is started in the current REPL buffer.

Its goal is to protect against looping infinitely when something goes wrong (see e.g. #9 (comment)). Most of the time, this approach works better than the obvious alternative (using timeouts).

Even if we create a file upon successful launch, that would happen after the error backtrace is printed to the REPL. So either we don't wait and declare the command as failed, or wait for... some?.. amount of time to see robe on.

The easiest workaround for you would be to launch the REPL and Robe server separately: first M-x inf-ruby-console-auto, and then M-x robe-start.

Going a bit more advanced route, we could try to process all the output coming from the REPL's startup first, before launching Robe, like:

diff --git a/robe.el b/robe.el
index dbe84f8..ddf6da0 100644
--- a/robe.el
+++ b/robe.el
@@ -120,7 +120,10 @@ project."
             (when (buffer-live-p ruby-buffer)
               (kill-buffer ruby-buffer))
             (inf-ruby-console-auto)
-            (set-window-configuration conf))
+            (set-window-configuration conf)
+            (while (not (buffer-local-value 'comint-last-prompt
+                                            (get-buffer inf-ruby-buffer)))
+              (accept-process-output (inf-ruby-proc))))
         (error "Aborted"))))
   (when (not robe-running)
     (let* ((proc (inf-ruby-proc))

The downside: if the REPL has a prompt that doesn't match inf-ruby-prompt-pattern, the command will hang forever.

@Hardtack
Copy link
Author

Actually, I also tried to launch REPL and Robe separately, but it is very annoying.
I have to launch REPL & Robe separately in some projects, and I can use normally with robe-start in some project.
Since robe doesn't kill ruby REPL after catching Error\\>, reusing this REPL can be less-annoying solution. All I have to do is just call robe-start twice!
I'm currently doing that with following modification

diff --git a/a/lib/robe.rb b/b/lib/robe.rb
index 8208e3d..a1e254f 100644
--- a/a/lib/robe.rb
+++ b/b/lib/robe.rb
@@ -6,7 +6,7 @@ module Robe
     attr_accessor :server

     def start(port = 0)
-      return if @server
+      return "robe on #{@server.port}" if @server

       @server = Server.new(Sash.new, port)

Without this modification, emacs will hang forever when re-using ruby REPL created by previous robe-start.

@dgutov
Copy link
Owner

dgutov commented May 18, 2016

I'm currently doing that with following modification

Good idea, pushed.

@dgutov dgutov changed the title Deal with initialization console message containing a word "Error" Allow the console to contain "Error" (or even a backtrace) on startup May 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants