Skip to content

Commit

Permalink
Report all missing EXTERNALs when validating, not just the first one …
Browse files Browse the repository at this point in the history
…it comes across
  • Loading branch information
joethephish committed Oct 12, 2016
1 parent 8760d71 commit 12256e9
Showing 1 changed file with 39 additions and 26 deletions.
65 changes: 39 additions & 26 deletions ink-engine-runtime/Story.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Copy link
@y-lohse

y-lohse Oct 16, 2016

Contributor

errorPreamble is never used afterwards, I suppose you intended to prepend it to message before pushing it to the error stack?

This comment has been minimized.

Copy link
@joethephish

joethephish Oct 17, 2016

Author Member

Oops, yes! Should be Error(errorPreamble + message); below. Will fix in the ink repo.

This comment has been minimized.

Copy link
@joethephish

joethephish Oct 17, 2016

Author Member

Although actually, I've removed the preamble altogether since line numbers aren't actually useful here (and would be annoying to list anyway). See change here: 7b983ce

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;
}

Expand All @@ -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);
}
}
}
}
Expand Down

0 comments on commit 12256e9

Please sign in to comment.