{"record":{"id":"d9f2e352cb39c34d","repo":"stride3d/stride","slug":"the-bestindent-parameter-must-be-between-0-and-1","errorCode":null,"errorMessage":"The bestIndent parameter must be between {0} and {1}.","messagePattern":"The bestIndent parameter must be between (.+?) and (.+?)\\.","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Yaml/Emitter.cs","lineNumber":151,"sourceCode":"\n        /// <summary>\n        /// Initializes a new instance of the <see cref=\"IEmitter\" /> class.\n        /// </summary>\n        /// <param name=\"output\">The <see cref=\"TextWriter\" /> where the emitter will write.</param>\n        /// <param name=\"bestIndent\">The preferred indentation.</param>\n        /// <param name=\"bestWidth\">The preferred text width.</param>\n        /// <param name=\"isCanonical\">If true, write the output in canonical form.</param>\n        /// <param name=\"forceIndentLess\">if set to <c>true</c> [always indent].</param>\n        /// <exception cref=\"System.ArgumentOutOfRangeException\">\n        /// bestIndent\n        /// or\n        /// bestWidth;The bestWidth parameter must be greater than bestIndent * 2.\n        /// </exception>\n        public Emitter(TextWriter output, int bestIndent = MinBestIndent, int bestWidth = int.MaxValue, bool isCanonical = false, bool forceIndentLess = false)\n        {\n            if (bestIndent < MinBestIndent || bestIndent > MaxBestIndent)\n            {\n                throw new ArgumentOutOfRangeException(\"bestIndent\", string.Format(CultureInfo.InvariantCulture, \"The bestIndent parameter must be between {0} and {1}.\", MinBestIndent, MaxBestIndent));\n            }\n\n            this.bestIndent = bestIndent;\n\n            if (bestWidth <= bestIndent*2)\n            {\n                throw new ArgumentOutOfRangeException(\"bestWidth\", \"The bestWidth parameter must be greater than bestIndent * 2.\");\n            }\n\n            this.bestWidth = bestWidth;\n\n            this.isCanonical = isCanonical;\n            this.forceIndentLess = forceIndentLess;\n\n            this.output = output;\n        }\n\n        /// <summary>","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Yaml/Emitter.cs#L133-L169","documentation":"The YAML Emitter constructor validates that bestIndent falls within MinBestIndent and MaxBestIndent and throws ArgumentOutOfRangeException otherwise. bestIndent controls the indentation used when emitting YAML.","triggerScenarios":"new Emitter(output, bestIndent: 0), bestIndent: 1, or any value above MaxBestIndent (e.g. 10).","commonSituations":"Configuring indentation from user settings or config files where 0 or an unvalidated number is passed; porting code that assumed indent 0 disables indentation.","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."],"exampleFix":"// before\nvar emitter = new Emitter(writer, bestIndent: 0);\n// after\nvar bestIndent = Math.Clamp(configuredIndent, Emitter.MinBestIndent, Emitter.MaxBestIndent);\nvar emitter = new Emitter(writer, bestIndent: bestIndent);","handlingStrategy":"validation","validationCode":"int bestIndent = Math.Clamp(configuredIndent, Emitter.MinBestIndent, Emitter.MaxBestIndent);\nvar emitter = new Emitter(writer, bestIndent: bestIndent);","typeGuard":"bool IsValidIndent(int v) => v >= Emitter.MinBestIndent && v <= Emitter.MaxBestIndent;","tryCatchPattern":"try { emitter = new Emitter(writer, bestIndent); }\ncatch (ArgumentOutOfRangeException ex) { emitter = new Emitter(writer); /* defaults */ }","preventionTips":["Clamp config-derived indent values","Omit bestIndent to use the default","Reference MinBestIndent/MaxBestIndent constants instead of magic numbers"],"tags":["yaml","argument-out-of-range"],"backgroundTag":"value-out-of-range","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}