diff options
author | Jacek Sieka <arnetheduck@gmail.com> | 2023-08-24 15:41:29 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-24 15:41:29 +0200 |
commit | bc9785c08d53c2f94f62738e541508592c9b3b24 (patch) | |
tree | 9cc3e8e695a465c830a9b1c1046f507b2de93534 /lib | |
parent | c56a712e7d54485b97df3b110ef148f5c12f2ab3 (diff) | |
download | Nim-bc9785c08d53c2f94f62738e541508592c9b3b24.tar.gz |
Fix `getAppFilename` exception handling (#22544)
* Fix `getAppFilename` exception handling avoid platform-dependendent error handling strategies * more fixes * space
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pure/os.nim | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/lib/pure/os.nim b/lib/pure/os.nim index 77dc3ca8f..13b103b92 100644 --- a/lib/pure/os.nim +++ b/lib/pure/os.nim @@ -8,7 +8,7 @@ # ## This module contains basic operating system facilities like -## retrieving environment variables, working with directories, +## retrieving environment variables, working with directories, ## running shell commands, etc. ## .. importdoc:: symlinks.nim, appdirs.nim, dirs.nim, ospaths2.nim @@ -624,10 +624,12 @@ when defined(haiku): else: result = "" -proc getAppFilename*(): string {.rtl, extern: "nos$1", tags: [ReadIOEffect], noWeirdTarget.} = +proc getAppFilename*(): string {.rtl, extern: "nos$1", tags: [ReadIOEffect], noWeirdTarget, raises: [].} = ## Returns the filename of the application's executable. ## This proc will resolve symlinks. ## + ## Returns empty string when name is unavailable + ## ## See also: ## * `getAppDir proc`_ ## * `getCurrentCompilerExe proc`_ @@ -657,14 +659,17 @@ proc getAppFilename*(): string {.rtl, extern: "nos$1", tags: [ReadIOEffect], noW if getExecPath2(result.cstring, size): result = "" # error! if result.len > 0: - result = result.expandFilename + try: + result = result.expandFilename + except OSError: + result = "" else: when defined(linux) or defined(aix): result = getApplAux("/proc/self/exe") elif defined(solaris): result = getApplAux("/proc/" & $getpid() & "/path/a.out") elif defined(genode): - raiseOSError(OSErrorCode(-1), "POSIX command line not supported") + result = "" # Not supported elif defined(freebsd) or defined(dragonfly) or defined(netbsd): result = getApplFreebsd() elif defined(haiku): @@ -676,7 +681,7 @@ proc getAppFilename*(): string {.rtl, extern: "nos$1", tags: [ReadIOEffect], noW # little heuristic that may work on other POSIX-like systems: if result.len == 0: - result = getApplHeuristic() + result = try: getApplHeuristic() except OSError: "" proc getAppDir*(): string {.rtl, extern: "nos$1", tags: [ReadIOEffect], noWeirdTarget.} = ## Returns the directory of the application's executable. |