diff --git a/docs/technical/web.md b/docs/technical/web.md index c13e24e9..27834a4f 100644 --- a/docs/technical/web.md +++ b/docs/technical/web.md @@ -85,9 +85,7 @@ Error messages may contain special tokens: The child errors themselves may be marked `$transparent`, etc. If an error has no child errors, this override is ignored. -Caveats: -* To override an error from a `then` block, the `@errorMessages` must be inside the `then` block - instead of adjacent. + Validation errors for `then` blocks are transparent by default, unless overridden. diff --git a/src/SMAPI.Web/Controllers/JsonValidatorController.cs b/src/SMAPI.Web/Controllers/JsonValidatorController.cs index 4f234449..d82765e7 100644 --- a/src/SMAPI.Web/Controllers/JsonValidatorController.cs +++ b/src/SMAPI.Web/Controllers/JsonValidatorController.cs @@ -213,7 +213,7 @@ namespace StardewModdingAPI.Web.Controllers private IEnumerable GetErrorModels(ValidationError error) { // skip through transparent errors - if (this.GetOverrideError(error) == this.TransparentToken && error.ChildErrors.Any()) + if (this.IsTransparentError(error)) { foreach (var model in error.ChildErrors.SelectMany(this.GetErrorModels)) yield return model; @@ -240,7 +240,7 @@ namespace StardewModdingAPI.Web.Controllers return message; // skip through transparent errors - while (this.GetOverrideError(error) == this.TransparentToken && error.ChildErrors.Count == 1) + if (this.IsTransparentError(error)) error = error.ChildErrors[0]; // get friendly representation of main error @@ -266,6 +266,19 @@ namespace StardewModdingAPI.Web.Controllers return message; } + /// Get whether a validation error should be omitted in favor of its child errors in user-facing error messages. + /// The error to check. + private bool IsTransparentError(ValidationError error) + { + if (!error.ChildErrors.Any()) + return false; + + string @override = this.GetOverrideError(error); + return + @override == this.TransparentToken + || (error.ErrorType == ErrorType.Then && @override == null); + } + /// Get an override error from the JSON schema, if any. /// The schema validation error. private string GetOverrideError(ValidationError error) diff --git a/src/SMAPI.Web/wwwroot/schemas/content-patcher.json b/src/SMAPI.Web/wwwroot/schemas/content-patcher.json index c7f882bc..315a1fb2 100644 --- a/src/SMAPI.Web/wwwroot/schemas/content-patcher.json +++ b/src/SMAPI.Web/wwwroot/schemas/content-patcher.json @@ -273,9 +273,6 @@ "required": [ "FromFile" ], "propertyNames": { "enum": [ "Action", "Target", "LogName", "Enabled", "When", "FromFile" ] - }, - "@errorMessages": { - "then": "$transparent" } } }, @@ -289,9 +286,6 @@ "required": [ "FromFile" ], "propertyNames": { "enum": [ "Action", "Target", "LogName", "Enabled", "When", "FromFile", "FromArea", "ToArea", "PatchMode" ] - }, - "@errorMessages": { - "then": "$transparent" } } }, @@ -304,9 +298,6 @@ "then": { "propertyNames": { "enum": [ "Action", "Target", "LogName", "Enabled", "When", "Fields", "Entries", "MoveEntries" ] - }, - "@errorMessages": { - "then": "$transparent" } } },