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

Improve error message for readFile/writeFile #6420

Open
dom96 opened this issue Sep 22, 2017 · 2 comments
Open

Improve error message for readFile/writeFile #6420

dom96 opened this issue Sep 22, 2017 · 2 comments

Comments

@dom96
Copy link
Contributor

dom96 commented Sep 22, 2017

Seeing the following:

cannot open: /home/blah/foo.txt

Is vague. It would be better to include more detailed info like:

cannot open: /home/blah/foo.txt. Permission Denied.
@capocasa
Copy link
Collaborator

Surprisingly nontrivial. So C fopen uses a global variable errno for that information, which is implemented as a thread local or funciton call when C threads are enabled by compiler flag on modern system, but not on all systems.

So I would suggest to change the Nim open wrapper (but not the fopen wrapper) to

(1) If Nim is compiled with threads=off, assume it's a global, look up the meaning, and add it to the exception, and also add the error code itself to the exception and create a list of constants to represent them
(2) if Nim is compiled with threads=on, implement whatever is in the errnoC macro i Nim, possibly platform specific. This is going to require a lot of test cases.

Comments welcome.

@Araq
Copy link
Member

Araq commented Dec 20, 2021

Once we moved io.nim out of system.nim (compatible with our version 2 goals) it should be easier to provide a more elaborate implementation, ideally one that avoids libc and calls into Windows/Posix directly.

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

3 participants