stride3d/stride · error · ArgumentOutOfRangeException
The bestWidth parameter must be greater than bestIndent * 2.
Error message
The bestWidth parameter must be greater than bestIndent * 2.
What it means
The Emitter constructor requires bestWidth to be strictly greater than bestIndent * 2; otherwise it throws ArgumentOutOfRangeException. The line width must leave room for at least two indentation levels.
Solutions
- Increase bestWidth so it is strictly greater than 2 * bestIndent.
- Reduce bestIndent when a narrow width is required.
- Validate/derive width from indent: bestWidth = Math.Max(bestWidth, 2 * bestIndent + 1).
Example fix
// before var emitter = new Emitter(writer, bestIndent: 40, bestWidth: 80); // 80 <= 80 // after var emitter = new Emitter(writer, bestIndent: 40, bestWidth: 81);
Defensive patterns
Strategy: validation
Validate before calling
if (bestWidth <= bestIndent * 2)
bestWidth = bestIndent * 2 + 1;
var emitter = new Emitter(writer, bestIndent, bestWidth); Type guard
bool IsValidWidth(int indent, int width) => width > indent * 2;
Try / catch
try { emitter = new Emitter(writer, bestIndent, bestWidth); }
catch (ArgumentOutOfRangeException) { emitter = new Emitter(writer, bestIndent, bestIndent * 2 + 1); } Prevention
- Derive width from indent with the > 2*indent rule
- Avoid combining large indents with narrow widths
- Validate both parameters together before construction
When it happens
Trigger: new Emitter(output, bestIndent: 4, bestWidth: 8) or any bestWidth <= bestIndent*2, e.g. bestWidth equal to or less than twice the indent.
Common situations: Setting a narrow line width (e.g. 80) together with a large indent such that width <= 2*indent; computing widths dynamically without validating the relationship.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Expecting value > 0
- The bestIndent parameter must be between
- The length must be positive.
- A negative number of mip maps is not allowed.
- A serializer factory selector must be sealed before being…
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/d6028d25b0e4b45c.
Report an issue: GitHub.
Appendix: source
Thrown at sources/core/Stride.Core.Yaml/Emitter.cs:158
/// <param name="isCanonical">If true, write the output in canonical form.</param>
/// <param name="forceIndentLess">if set to <c>true</c> [always indent].</param>
/// <exception cref="System.ArgumentOutOfRangeException">
/// bestIndent
/// or
/// bestWidth;The bestWidth parameter must be greater than bestIndent * 2.
/// </exception>
public Emitter(TextWriter output, int bestIndent = MinBestIndent, int bestWidth = int.MaxValue, bool isCanonical = false, bool forceIndentLess = false)
{
if (bestIndent < MinBestIndent || bestIndent > MaxBestIndent)
{
throw new ArgumentOutOfRangeException("bestIndent", string.Format(CultureInfo.InvariantCulture, "The bestIndent parameter must be between {0} and {1}.", MinBestIndent, MaxBestIndent));
}
this.bestIndent = bestIndent;
if (bestWidth <= bestIndent*2)
{
throw new ArgumentOutOfRangeException("bestWidth", "The bestWidth parameter must be greater than bestIndent * 2.");
}
this.bestWidth = bestWidth;
this.isCanonical = isCanonical;
this.forceIndentLess = forceIndentLess;
this.output = output;
}
/// <summary>
/// Gets or sets a value indicating whether [always indent].
/// </summary>
/// <value><c>true</c> if [always indent]; otherwise, <c>false</c>.</value>
public bool ForceIndentLess { get { return forceIndentLess; } set { forceIndentLess = value; } }
private void Write(char value)View on GitHub (pinned to 96fad776d2)