Skip to content

Commit ddae10f

Browse files
author
Kapil Borle
committed
Add TrySaveModule method to ModuleDependencyHandler class
1 parent ce31b43 commit ddae10f

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

Engine/Generic/ModuleDependencyHandler.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,20 @@ public bool ModuleExists(string moduleName)
245245
throw new NotImplementedException();
246246
}
247247

248+
public bool TrySaveModule(string moduleName)
249+
{
250+
try
251+
{
252+
SaveModule(moduleName);
253+
return true;
254+
}
255+
catch
256+
{
257+
// log exception to verbose
258+
return false;
259+
}
260+
}
261+
248262
// TODO Do not use find module because it leads to two queries to the server
249263
// instead use save module and check if it couldn't find the module
250264
// TODO Add a TrySaveModule method

Engine/ScriptAnalyzer.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,17 +1327,13 @@ private IEnumerable<DiagnosticRecord> AnalyzeFile(string filePath)
13271327
bool parseAgain = false;
13281328
if (moduleHandler != null && errors != null && errors.Length > 0)
13291329
{
1330-
foreach (ParseError error in errors)
1330+
foreach (ParseError error in errors.Where(IsModuleNotFoundError))
13311331
{
1332-
if (IsModuleNotFoundError(error))
1332+
var moduleName = ModuleDependencyHandler.GetModuleNameFromErrorExtent(error, scriptAst);
1333+
if (moduleName != null
1334+
&& moduleHandler.TrySaveModule(moduleName))
13331335
{
1334-
var moduleName = ModuleDependencyHandler.GetModuleNameFromErrorExtent(error, scriptAst);
1335-
if (moduleName != null)
1336-
{
1337-
moduleHandler.SaveModule(moduleName);
1338-
// if successfully saved
1339-
parseAgain = true;
1340-
}
1336+
parseAgain = true;
13411337
}
13421338
}
13431339
}
@@ -1364,7 +1360,6 @@ private IEnumerable<DiagnosticRecord> AnalyzeFile(string filePath)
13641360
{
13651361
string manyParseErrorMessage = String.Format(CultureInfo.CurrentCulture, Strings.ParserErrorMessage, System.IO.Path.GetFileName(filePath));
13661362
this.outputWriter.WriteError(new ErrorRecord(new ParseException(manyParseErrorMessage), manyParseErrorMessage, ErrorCategory.ParserError, filePath));
1367-
13681363
return new List<DiagnosticRecord>();
13691364
}
13701365
}

0 commit comments

Comments
 (0)