-
Notifications
You must be signed in to change notification settings - Fork 499
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Report all missing EXTERNALs when validating, not just the first one …
…it comes across
- Loading branch information
1 parent
8760d71
commit 12256e9
Showing
1 changed file
with
39 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1405,25 +1405,50 @@ public void UnbindExternalFunction(string funcName) | |
/// </summary> | ||
public void ValidateExternalBindings() | ||
{ | ||
ValidateExternalBindings (_mainContentContainer); | ||
var missingExternals = new HashSet<string>(); | ||
|
||
ValidateExternalBindings (_mainContentContainer, missingExternals); | ||
_hasValidatedExternals = true; | ||
|
||
// No problem! Validation complete | ||
if( missingExternals.Count == 0 ) { | ||
_hasValidatedExternals = true; | ||
} | ||
|
||
// Error for all missing externals | ||
else { | ||
var message = string.Format("Missing function binding for external{0}: '{1}' {2}", | ||
missingExternals.Count > 1 ? "s" : string.Empty, | ||
string.Join("', '", missingExternals.ToArray()), | ||
allowExternalFunctionFallbacks ? ", and no fallback ink function found." : " (ink fallbacks disabled)" | ||
); | ||
|
||
string errorPreamble = "ERROR: "; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
joethephish
Author
Member
|
||
if (_mainContentContainer.debugMetadata != null) { | ||
errorPreamble += string.Format ("'{0}' line {1}: ", _mainContentContainer.debugMetadata.fileName, _mainContentContainer.debugMetadata.startLineNumber); | ||
} | ||
|
||
Error(message); | ||
} | ||
} | ||
|
||
void ValidateExternalBindings(Container c) | ||
void ValidateExternalBindings(Container c, HashSet<string> missingExternals) | ||
{ | ||
foreach (var innerContent in c.content) { | ||
ValidateExternalBindings (innerContent); | ||
var container = innerContent as Container; | ||
if( container == null || !container.hasValidName ) | ||
ValidateExternalBindings (innerContent, missingExternals); | ||
} | ||
foreach (var innerKeyValue in c.namedContent) { | ||
ValidateExternalBindings (innerKeyValue.Value as Runtime.Object); | ||
ValidateExternalBindings (innerKeyValue.Value as Runtime.Object, missingExternals); | ||
} | ||
} | ||
|
||
void ValidateExternalBindings(Runtime.Object o) | ||
void ValidateExternalBindings(Runtime.Object o, HashSet<string> missingExternals) | ||
{ | ||
var container = o as Container; | ||
if (container) { | ||
ValidateExternalBindings (container); | ||
ValidateExternalBindings (container, missingExternals); | ||
return; | ||
} | ||
|
||
|
@@ -1432,26 +1457,14 @@ void ValidateExternalBindings(Runtime.Object o) | |
var name = divert.targetPathString; | ||
|
||
if (!_externals.ContainsKey (name)) { | ||
|
||
INamedContent fallbackFunction = null; | ||
bool fallbackFound = mainContentContainer.namedContent.TryGetValue (name, out fallbackFunction); | ||
|
||
string message = null; | ||
if (!allowExternalFunctionFallbacks) | ||
message = "Missing function binding for external '" + name + "' (ink fallbacks disabled)"; | ||
else if( !fallbackFound ) { | ||
message = "Missing function binding for external '" + name + "', and no fallback ink function found."; | ||
} | ||
|
||
if (message != null) { | ||
string errorPreamble = "ERROR: "; | ||
if (divert.debugMetadata != null) { | ||
errorPreamble += string.Format ("'{0}' line {1}: ", divert.debugMetadata.fileName, divert.debugMetadata.startLineNumber); | ||
} | ||
|
||
throw new StoryException (errorPreamble + message); | ||
} | ||
|
||
if( allowExternalFunctionFallbacks ) { | ||
bool fallbackFound = mainContentContainer.namedContent.ContainsKey(name); | ||
if( !fallbackFound ) { | ||
missingExternals.Add(name); | ||
} | ||
} else { | ||
missingExternals.Add(name); | ||
} | ||
} | ||
} | ||
} | ||
|
errorPreamble
is never used afterwards, I suppose you intended to prepend it tomessage
before pushing it to the error stack?