Skip to content
This repository has been archived by the owner on Dec 28, 2022. It is now read-only.

Preview pane throws an exception when Asciidoctor is trying to write something to stdout #159

Closed
ggrossetie opened this issue May 31, 2016 · 14 comments

Comments

@ggrossetie
Copy link
Member

Description

Preview pane throws an exception when Asciidoctor is trying to write something to stdout.

Screenshots

boom

Syntax example

= Test

== Title

==== Boom!

Stack trace

I don't really know why the method warn is calling in the end fs.writeSync (see the stack trace below).
Operation is not permitted on Windows but maybe this is working on Linux ? (I'm using Windows 10 on this machine)

EPERM: operation not permitted, write Error: EPERM: operation not permitted, write
    at Error (native)
    at Object.fs.writeSync (fs.js:706:20)
    at SyncWriteStream.write (fs.js:2059:6)
    at $IO.write_proc (C:\Users\ggrossetie\.atom\packages\asciidoc-preview\node_modules\asciidoctor.js\node_modules\opal-npm-wrapper\index.js:18516:89)
    at $IO.$write (C:\Users\ggrossetie\.atom\packages\asciidoc-preview\node_modules\asciidoctor.js\node_modules\opal-npm-wrapper\index.js:18413:12)
    at $IO.$puts (C:\Users\ggrossetie\.atom\packages\asciidoc-preview\node_modules\asciidoctor.js\node_modules\opal-npm-wrapper\index.js:18467:16)
    at SingletonClass_alloc.$warn (C:\Users\ggrossetie\.atom\packages\asciidoc-preview\node_modules\asciidoctor.js\node_modules\opal-npm-wrapper\index.js:4255:43)
    at SingletonClass_alloc.$next_section (C:\Users\ggrossetie\.atom\packages\asciidoc-preview\node_modules\asciidoctor.js\dist\npm\asciidoctor-core.min.js:384:236)
    at SingletonClass_alloc.$next_section (C:\Users\ggrossetie\.atom\packages\asciidoc-preview\node_modules\asciidoctor.js\dist\npm\asciidoctor-core.min.js:385:17)
    at SingletonClass_alloc.$parse (C:\Users\ggrossetie\.atom\packages\asciidoc-preview\node_modules\asciidoctor.js\dist\npm\asciidoctor-core.min.js:371:247)
    at f.$parse (C:\Users\ggrossetie\.atom\packages\asciidoc-preview\node_modules\asciidoctor.js\dist\npm\asciidoctor-core.min.js:323:183)
    at module_constructor.$load (C:\Users\ggrossetie\.atom\packages\asciidoc-preview\node_modules\asciidoctor.js\dist\npm\asciidoctor-core.min.js:642:89)
    at module_constructor.<anonymous> (C:\Users\ggrossetie\.atom\packages\asciidoc-preview\node_modules\asciidoctor.js\dist\npm\asciidoctor-core.min.js:645:369)
    at Object.module.exports (file:///C:/Users/ggrossetie/.atom/packages/asciidoc-preview/lib/worker.coffee:30:22)
    at process.<anonymous> (C:\Users\ggrossetie\AppData\Local\atom\app-1.7.4\resources\app.asar\src\task-bootstrap.js:84:10)
    at emitTwo (events.js:87:13)
    at process.emit (events.js:172:7)
    at handleMessage (internal/child_process.js:686:10)
    at Pipe.channel.onread (internal/child_process.js:440:11)
@ldez
Copy link
Member

ldez commented May 31, 2016

Have you try with my new branch?

Works on Linux.

@ggrossetie
Copy link
Member Author

Have you try with my new branch?

Your new branch ? I'm using version 2.1.2

Works on Linux.

Do you have any message on the developer console ?
Here is the last line called in Asciidoctor.js:

(($a = [typeof(process) === 'object' && !process.browser ? function(s){process.stderr.write(s)} : function(s){console.warn(s)}]), $b = $scope.get('STDERR'), $b['$write_proc='].apply($b, $a), $a[$a.length-1]);

@ldez
Copy link
Member

ldez commented May 31, 2016

I got a warning:

asciidoctor: /usr/share/atom/resources/app.asar/src/task.js:91 
WARNING: <stdin>: line 6: section title out of sequence: expected level 2, got level 3

@ggrossetie
Copy link
Member Author

Ok thanks, I will test on an other machine with Windows 7

@ldez
Copy link
Member

ldez commented Jun 6, 2016

reproduces with Win7

@ldez
Copy link
Member

ldez commented Jun 6, 2016

another way to crash:

[source, js]
----
console.log("toto") <2>
----
<1> test

I confirm the problem: each time Asciidoctor.js is trying to write something to stdout...

@ldez
Copy link
Member

ldez commented Jun 7, 2016

Waiting for asciidoctor/asciidoctor.js#187

@ggrossetie
Copy link
Member Author

electron/electron#2033 (comment)

I think I can workaround this issue in Opal with a fallback on console or something more suited for Electron. Wdyt ?

@ldez
Copy link
Member

ldez commented Jun 11, 2016

It's exactly what I'm trying to do! But Opal produce very obscure code...

@ggrossetie
Copy link
Member Author

ggrossetie commented Jun 11, 2016

I think the easiest way to provide an Electron implementation is to create a new io.rb file in Asciidoctor.js. We are already doing something similar with Nashorn, see: https://github.com/asciidoctor/asciidoctor.js/blob/master/lib/asciidoctor/opal_ext/nashorn/io.rb

Then you'll need to detect that you are running in an Electron environment and require this new file: https://github.com/asciidoctor/asciidoctor.js/blob/master/lib/asciidoctor/opal_ext.rb

Let me know if you have any questions.

We could even show a (Tray)[http://electron.atom.io/docs/api/tray/] or a (Dialog)[http://electron.atom.io/docs/api/dialog/] to display the error/warning message 😄

@ldez
Copy link
Member

ldez commented Jun 11, 2016

Is it possible to provided a external custom extension point for IO ?
Because this problem occurs only with Windows.

@ldez
Copy link
Member

ldez commented Jun 11, 2016

To know if it's electron: process.versions.electron
To know if it's Windows: process.platform === 'win32'

@ldez
Copy link
Member

ldez commented Jun 11, 2016

It's a choice to not use notification/tray/dialog because it's not the role of the preview to do that.
I asked to capture error for create a linter package http://atomlinter.github.io/

@ldez
Copy link
Member

ldez commented Jun 11, 2016

For now, I have made a workaround with a hook of Node's standard stream. see #175.

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

No branches or pull requests

2 participants