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

Error: unhandled exception: errno: 9 `Bad file descriptor' [IOError] #16502

Closed
retsyo opened this issue Dec 29, 2020 · 5 comments
Closed

Error: unhandled exception: errno: 9 `Bad file descriptor' [IOError] #16502

retsyo opened this issue Dec 29, 2020 · 5 comments

Comments

@retsyo
Copy link

retsyo commented Dec 29, 2020

I am using latest cloned&built nim

$ nim
Nim Compiler Version 1.5.1 [Windows: amd64]
Compiled at 2020-12-29
Copyright (c) 2006-2020 by Andreas Rumpf

Example

echo 1

Current Output

when I compile the a.nim with nim c -r --app:gui a.nim, I get an error msgbox

R:\a.nim(1)
a
E\msys64\home\USER\_nim\nim\lib\system\io.nim(791) echoBinSafe
E:\msys64\home\USER\_nim\nim\lib\system\io.nim(156) checkErr
E:\msys64\home\USER\_niminim\lib\system\io.nim(139) raiseEIO
Error: unhandled exception: errno: 9 `'Bad file descriptor` [IOError]

when I compile a.nim as nim c -r a.nim, I see

1

as expected

Expected Output

yes, I know --app:gui means to compile a GUI app without console, so I expect nim c -r --app:gui a.nim runs but without error msgbox. Why do I need this? Because I write some echo xx in my app which are used for debugging. When the app is finished, I need to release a GUI app to the user without console, but I am lazy to remove the echo xx statements.

thanks

@ringabout
Copy link
Member

Workaround:
Use nim c -r --app:gui -d:nimLegacyEchoNoRaise

@ringabout
Copy link
Member

see #16367

@timotheecour
Copy link
Member

timotheecour commented Dec 29, 2020

#16367 was still correct to raise; -d:nimLegacyEchoNoRaise is indeed usable here, but you probably should use:

template myEcho(args: varargs[untyped]): untyped =
  # adapt if needed so echo still renders at CT using `when nimvm`
  when appType == "gui": discard
  else: echo(args)

(or, if it's meaningful to support, echo at RT with app:gui could be implemented by rendering a window , eg System.Windows.MessageBox https://mcpmag.com/articles/2016/06/09/display-gui-message-boxes-in-powershell.aspx)

@Clyybber
Copy link
Contributor

Clyybber commented Dec 29, 2020

IMO the change should be reverted, what worth is it raising if you can't display the exception (on platforms where we don't have this messagebox)?
It's only useful if you intend to catch the exception, but since all code that relies on that will be new code, the raising version of echo should be a new proc.

@ringabout
Copy link
Member

ringabout commented Dec 30, 2020

(or, if it's meaningful to support, echo at RT with app:gui could be implemented by rendering a window , eg System.Windows.MessageBox

no

It is easy to fix. Just adding not defined(guiapp) is enough without reverting original PR.

echo 1

In windows, I got a messagebox and I can catch this exception.
image

Note that app:gui is specific to Windows
see disable --app:gui for non Windows targets; fixes #2576

ringabout added a commit to ringabout/Nim that referenced this issue Dec 30, 2020
@ringabout ringabout mentioned this issue Dec 30, 2020
@Araq Araq closed this as completed in 2f4d00f Dec 30, 2020
mildred pushed a commit to mildred/Nim that referenced this issue Jan 11, 2021
ardek66 pushed a commit to ardek66/Nim that referenced this issue Mar 26, 2021
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

4 participants