diff options
author | Jake Leahy <jake@leahy.dev> | 2023-12-02 15:29:10 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-02 05:29:10 +0100 |
commit | a25843cf8010db92de4e95e734e11208f36fea86 (patch) | |
tree | eba0396e0fb0ae51a4caa5cacca7949a95b106e4 | |
parent | 0d24f765461785e5648ee580e0a4158eb344ee97 (diff) | |
download | Nim-a25843cf8010db92de4e95e734e11208f36fea86.tar.gz |
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](https://github.com/ire4ever1190/Nim/blob/0dc12ec24b7902ef0023a9e694faa11bcf99e257/compiler/options.nim#L785-L788)
-rw-r--r-- | compiler/options.nim | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/compiler/options.nim b/compiler/options.nim index 9282247c3..45ed8c23e 100644 --- a/compiler/options.nim +++ b/compiler/options.nim @@ -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 = |