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:
Jake Leahy
2023-12-02 15:29:10 +11:00
committed by GitHub
parent 0d24f76546
commit a25843cf80

View File

@@ -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 =