stride3d/stride · error · ArgumentOutOfRangeException
The bestIndent parameter must be between
Error message
The bestIndent parameter must be between {0} and {1}. What it means
The YAML Emitter constructor validates that bestIndent falls within MinBestIndent and MaxBestIndent and throws ArgumentOutOfRangeException otherwise. bestIndent controls the indentation used when emitting YAML.
Solutions
- Pass a bestIndent value within the allowed range (check MinBestIndent/MaxBestIndent constants; typically 2-9).
- Clamp user-supplied configuration before constructing the emitter.
- Use the default parameter (omit bestIndent) unless you specifically need custom indentation.
Example fix
// before var emitter = new Emitter(writer, bestIndent: 0); // after var bestIndent = Math.Clamp(configuredIndent, Emitter.MinBestIndent, Emitter.MaxBestIndent); var emitter = new Emitter(writer, bestIndent: bestIndent);
Defensive patterns
Strategy: validation
Validate before calling
int bestIndent = Math.Clamp(configuredIndent, Emitter.MinBestIndent, Emitter.MaxBestIndent); var emitter = new Emitter(writer, bestIndent: bestIndent);
Type guard
bool IsValidIndent(int v) => v >= Emitter.MinBestIndent && v <= Emitter.MaxBestIndent;
Try / catch
try { emitter = new Emitter(writer, bestIndent); }
catch (ArgumentOutOfRangeException ex) { emitter = new Emitter(writer); /* defaults */ } Prevention
- Clamp config-derived indent values
- Omit bestIndent to use the default
- Reference MinBestIndent/MaxBestIndent constants instead of magic numbers
When it happens
Trigger: new Emitter(output, bestIndent: 0), bestIndent: 1, or any value above MaxBestIndent (e.g. 10).
Common situations: Configuring indentation from user settings or config files where 0 or an unvalidated number is passed; porting code that assumed indent 0 disables indentation.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- Expecting value > 0
- The bestWidth parameter must be greater than bestIndent * 2.
- 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/d9f2e352cb39c34d.
Report an issue: GitHub.
Appendix: source
Thrown at sources/core/Stride.Core.Yaml/Emitter.cs:151
/// <summary>
/// Initializes a new instance of the <see cref="IEmitter" /> class.
/// </summary>
/// <param name="output">The <see cref="TextWriter" /> where the emitter will write.</param>
/// <param name="bestIndent">The preferred indentation.</param>
/// <param name="bestWidth">The preferred text width.</param>
/// <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>View on GitHub (pinned to 96fad776d2)