mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
Show proper error message if trying to run a Nim file in a directory that doesn't exist (#23017)
For example with the command `nim r foo/bar.nim`, if `foo/` doesn't
exist then it shows this message
```
oserrors.nim(92) raiseOSError
Error: unhandled exception: No such file or directory
Additional info: foo [OSError]
```
After PR it shows
```
Error: cannot open 'foo/bar.nim'
```
Which makes it line up with the error message if `foo/` did exist but
`bar.nim` didn't. Does this by using the same logic for [handling if the
file doesn't
exist](0dc12ec24b/compiler/options.nim (L785-L788))
This commit is contained in:
@@ -789,7 +789,10 @@ proc setFromProjectName*(conf: ConfigRef; projectName: string) =
|
||||
conf.projectFull = AbsoluteFile projectName
|
||||
let p = splitFile(conf.projectFull)
|
||||
let dir = if p.dir.isEmpty: AbsoluteDir getCurrentDir() else: p.dir
|
||||
conf.projectPath = AbsoluteDir canonicalizePath(conf, AbsoluteFile dir)
|
||||
try:
|
||||
conf.projectPath = AbsoluteDir canonicalizePath(conf, AbsoluteFile dir)
|
||||
except OSError:
|
||||
conf.projectPath = dir
|
||||
conf.projectName = p.name
|
||||
|
||||
proc removeTrailingDirSep*(path: string): string =
|
||||
|
||||
Reference in New Issue
Block a user