nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.55k stars 1.47k forks source link

nim e fails with incorrect error if file does not exist or if script file gets deleted during execution #11165

Closed genotrance closed 5 years ago

genotrance commented 5 years ago

Similar to how batch files die if the file gets modified or deleted during execution.

If you have a nimscript file a.nims with:

rmFile("a.nims")

Running this script gives random error about filename. This affected nimble's nocompiler feature (removing compiler from nimble). As noted by @andreaferretti in https://github.com/nim-lang/nimble/pull/635#issuecomment-488645566, since nimble is being called recursively, the nims file copied by parent process gets deleted by child process.

I am fixing this in nimble separately (don't delete if you didn't copy it in the first place) but it seems this might bite others as well. The use case might not be too common but interesting to document at the very least.

Error (with stack trace) is:

# > nim_temp e a.nims
(1, 21) Error: undeclared identifier: 'a'
Traceback (most recent call last)
nim.nim(98)              nim
nim.nim(75)              handleCmdLine
cmdlinehelper.nim(92)    loadConfigsAndRunMainCommand
main.nim(347)            mainCommand
main.nim(156)            commandEval
main.nim(149)            evalNim
passes.nim(66)           carryPasses
passes.nim(57)           carryPass
sem.nim(603)             myProcess
sem.nim(571)             semStmtAndGenerateGenerics
semstmts.nim(2159)       semStmt
semexprs.nim(939)        semExprNoType
semexprs.nim(2657)       semExpr
semstmts.nim(2099)       semStmtList
semexprs.nim(2561)       semExpr
semexprs.nim(2165)       semMagic
semexprs.nim(920)        semDirectOp
semexprs.nim(770)        semOverloadedCallAnalyseEffects
semcall.nim(524)         semOverloadedCall
semcall.nim(326)         resolveOverloads
semcall.nim(93)          pickBestCandidate
sigmatch.nim(2462)       matches
sigmatch.nim(2402)       matchesAux
sigmatch.nim(2214)       prepareOperand
semexprs.nim(49)         semOperand
semexprs.nim(2561)       semExpr
semexprs.nim(2165)       semMagic
semexprs.nim(920)        semDirectOp
semexprs.nim(770)        semOverloadedCallAnalyseEffects
semcall.nim(524)         semOverloadedCall
semcall.nim(326)         resolveOverloads
semcall.nim(93)          pickBestCandidate
sigmatch.nim(2462)       matches
sigmatch.nim(2402)       matchesAux
sigmatch.nim(2214)       prepareOperand
semexprs.nim(49)         semOperand
semexprs.nim(2512)       semExpr
semexprs.nim(1356)       semFieldAccess
semexprs.nim(1210)       builtinFieldAccess
lookups.nim(328)         qualifiedLookUp
lookups.nim(317)         qualifiedLookUp
lookups.nim(272)         errorUndeclaredIdentifier
msgs.nim(530)            localError
msgs.nim(515)            liMessage
msgs.nim(346)            handleError
msgs.nim(331)            quit
timotheecour commented 5 years ago

maybe related: nim e main.nim fails with a really bad error msg when extension is wrong (nim instead of nims):

./bin/nim e --skipUserCfg $timn_D/tests/nim/all/t0538.nim
Hint: used config file '/Users/timothee/git_clone/nim/Nim_devel/config/nim.cfg' [Conf]
Hint: used config file '/Users/timothee/git_clone/nim/timn/nim.cfg' [Conf]
Hint: used config file '/Users/timothee/git_clone/nim/Nim_devel/config/config.nims' [Conf]
Hint: system [Processing]
Hint: widestrs [Processing]
Hint: io [Processing]
Hint: stdin [Processing]
(1, 57) Error: undeclared identifier: '//'

passing --verbosity:3 is equally unhelpful

genotrance commented 5 years ago

Just to clarify again - the way I found the issue is not the typical use case. Fact is that if you run nim e with a bad filename, you get an unrelated error and it isn't clear what happened. You can also recreate the issue by deleting the file at runtime.

(1, 21) Error: undeclared identifier: 'a' suggests that there's a problem in the file contents, not that the file doesn't even exist or got deleted during execution.

Similar to @timotheecour's report, .nim extension is not support for nim e but you don't get a helpful error.

Araq commented 5 years ago

Should be fixed by https://github.com/nim-lang/Nim/pull/11961