Skip to content

Commit 50f19ef

Browse files
author
Victor R. Escobar
committed
Reporting which file has not been found in a proper way. closes #755
1 parent f15854f commit 50f19ef

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

transcrypt/__main__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ def setExitCode (anExitCode):
9090

9191
utils.log (True, '\n{} (TM) Python to JavaScript Small Sane Subset Transpiler Version {}\n', __envir__.transpiler_name.capitalize (), __envir__.transpiler_version)
9292
utils.log (True, 'Copyright (C) Geatec Engineering. License: Apache 2.0\n\n')
93-
9493
utils.log (True, '\n')
94+
9595
licensePath = '{}/{}'.format (transpilerDir, 'license_reference.txt')
9696
if not os.path.isfile (licensePath):
9797
utils.log (True, 'Error: missing license reference file\n')
@@ -109,8 +109,9 @@ def setExitCode (anExitCode):
109109
if utils.commandArgs.star:
110110
webbrowser.open ('https://github.com/qquick/Transcrypt')
111111

112-
if not utils.commandArgs.source:
113-
return setExitCode (exitSourceNotGiven) # Should never be here, dealth with by command arg checks already
112+
if not os.path.isfile(utils.commandArgs.source):
113+
utils.log (True, 'File not found: {}'.format(utils.commandArgs.source))
114+
return setExitCode (exitSourceNotGiven) # apparently not properly dealt by argParse
114115

115116
if utils.commandArgs.source.endswith ('.py') or utils.commandArgs.source.endswith ('.js'):
116117
utils.commandArgs.source = utils.commandArgs.source [:-3] # Ignore extension

transcrypt/modules/org/transcrypt/utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,12 @@ def __str__ (self):
209209

210210
# After that, report the module and line that caused the error
211211
# result += '\n\tFile \'{}\', line {}, namely:'.format (str (program.importStack [-1][0] .sourcePath), self.lineNr)
212-
result += '\n\tFile \'{}\', line {}, namely:'.format (str (program.importStack [-1][0] .name), self.lineNr)
212+
try:
213+
name = str(program.importStack [-1][0] .name)
214+
except:
215+
# most probably the does not exist or for whatever reason the stack is empty
216+
name = "<unknown>"
217+
result += '\n\tFile \'{}\', line {}, namely:'.format(name, self.lineNr)
213218

214219
# And, lastly, report the error message
215220
result += '\n\t{}'.format (self.message)

0 commit comments

Comments
 (0)