Better error reporting if unable to find module

This commit is contained in:
Deukhoofd 2018-12-07 14:41:19 +01:00
parent c1da2dd5b7
commit edd352e62a
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
3 changed files with 19 additions and 4 deletions

View File

@ -248,11 +248,20 @@ namespace Upsilon.Binder
{ {
var moduleName = be.Value.ToString(); var moduleName = be.Value.ToString();
var module = _script.Options.ModuleHandler.GetModule(_script, moduleName); var module = _script.Options.ModuleHandler.GetModule(_script, moduleName);
foreach (var moduleVariable in module.Scope.Variables) if (module == null)
{ {
if (moduleVariable.Value.Local) _diagnostics.LogError(
continue; $"Can't find module '{moduleName}' in folder '{_script.Options.ScriptLoader.ModulesPath}'",
Scope.AssignToNearest(moduleVariable.Value); parameter.Span);
}
else
{
foreach (var moduleVariable in module.Scope.Variables)
{
if (moduleVariable.Value.Local)
continue;
Scope.AssignToNearest(moduleVariable.Value);
}
} }
} }
} }

View File

@ -14,6 +14,8 @@ namespace Upsilon
return module; return module;
var moduleScript = script.Options.ScriptLoader.LoadModule(name); var moduleScript = script.Options.ScriptLoader.LoadModule(name);
if (moduleScript == null)
return null;
var parsed = Executor.ContinueWith(script, moduleScript); var parsed = Executor.ContinueWith(script, moduleScript);
module = parsed.Bind(); module = parsed.Bind();
_cachedModules.Add(name, module); _cachedModules.Add(name, module);

View File

@ -47,6 +47,10 @@ namespace Upsilon.StandardLibraries
{ {
var file = fileName.Value; var file = fileName.Value;
var module = script.Options.ModuleHandler.GetModule(script, file); var module = script.Options.ModuleHandler.GetModule(script, file);
if (module == null)
{
throw new Exception($"Unable to load module {file} at path {script.Options.ScriptLoader.ModulesPath}");
}
var s = Executor.ContinueWith(script, module); var s = Executor.ContinueWith(script, module);
var val = s.Evaluate(); var val = s.Evaluate();
return val != null ? val.ToScriptType() : new ScriptNull(); return val != null ? val.ToScriptType() : new ScriptNull();