{"record":{"id":"c64bd95dc38eae7d","repo":"microsoft/aspire","slug":"the-inspect-mode-must-be-a-defined-denoinspectmode-value","errorCode":null,"errorMessage":"The inspect mode must be a defined DenoInspectMode value.","messagePattern":"The inspect mode must be a defined DenoInspectMode value\\.","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.JavaScript/DenoHostingExtensions.cs","lineNumber":318,"sourceCode":"\n    /// <summary>Enables a Deno inspector mode, optionally at <paramref name=\"hostPort\"/> (for example <c>127.0.0.1:9229</c>).</summary>\n    /// <param name=\"builder\">The Deno app resource builder.</param>\n    /// <param name=\"mode\">The inspector mode to enable.</param>\n    /// <param name=\"hostPort\">The optional inspector host:port value.</param>\n    /// <returns>A reference to the <see cref=\"IResourceBuilder{T}\"/>.</returns>\n    /// <exception cref=\"ArgumentOutOfRangeException\">Thrown when <paramref name=\"mode\"/> is not a defined <see cref=\"DenoInspectMode\"/> value.</exception>\n    /// <ats-returns>The resource builder.</ats-returns>\n    [AspireExport]\n    [Experimental(\"ASPIREDENO001\", UrlFormat = \"https://aka.ms/aspire/diagnostics/{0}\")]\n    public static IResourceBuilder<DenoAppResource> WithDenoInspect(\n        this IResourceBuilder<DenoAppResource> builder,\n        DenoInspectMode mode = DenoInspectMode.Inspect,\n        string? hostPort = null)\n    {\n        ArgumentNullException.ThrowIfNull(builder);\n        if (!Enum.IsDefined(mode))\n        {\n            throw new ArgumentOutOfRangeException(nameof(mode), mode, \"The inspect mode must be a defined DenoInspectMode value.\");\n        }\n\n        var annotation = GetOrAddDenoAnnotation(builder);\n        annotation.Inspect = mode;\n        annotation.InspectHostPort = string.IsNullOrEmpty(hostPort) ? null : hostPort;\n        return builder;\n    }\n\n    // ---- Modes ------------------------------------------------------------------------------\n\n    /// <summary>Selects the <c>deno run &lt;entrypoint&gt;</c> mode (the default).</summary>\n    /// <param name=\"builder\">The Deno app resource builder.</param>\n    /// <returns>A reference to the <see cref=\"IResourceBuilder{T}\"/>.</returns>\n    /// <ats-returns>The resource builder.</ats-returns>\n    [AspireExport]\n    [Experimental(\"ASPIREDENO001\", UrlFormat = \"https://aka.ms/aspire/diagnostics/{0}\")]\n    public static IResourceBuilder<DenoAppResource> WithDenoRun(this IResourceBuilder<DenoAppResource> builder)\n    {","sourceCodeStart":300,"sourceCodeEnd":336,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.JavaScript/DenoHostingExtensions.cs#L300-L336","documentation":"WithDenoInspect validates that the DenoInspectMode is a defined enum member before storing it on the annotation, since the mode is translated into '--inspect' / '--inspect-brk[=host:port]' arguments at launch. An undefined value would render an invalid flag, so it throws ArgumentOutOfRangeException.","triggerScenarios":"Calling WithDenoInspect with a mode cast from an int/string that is not a defined DenoInspectMode (Inspect/InspectBrk), typically from config parsing or version-mismatched assemblies.","commonSituations":"Mapping debugger settings strings to the enum with direct casts; stale builds after enum changes; custom tooling constructing the enum numerically.","solutions":["Use DenoInspectMode.Inspect or DenoInspectMode.InspectBrk (or the overload default).","Validate with Enum.IsDefined before casting config input.","Rebuild with matching Aspire.Hosting.JavaScript versions.","Extend the flag-generation mapping in the library when adding new modes."],"exampleFix":"// before\nvar mode = (DenoInspectMode)Enum.Parse(typeof(DenoInspectMode), config, ignoreCase: true);\nresource.WithDenoInspect(mode);\n// after\nif (!Enum.TryParse<DenoInspectMode>(config, ignoreCase: true, out var mode) || !Enum.IsDefined(mode))\n    throw new ArgumentException($\"Unknown inspect mode '{config}'.\");\nresource.WithDenoInspect(mode);","handlingStrategy":"validation","validationCode":"if (!Enum.IsDefined(typeof(DenoInspectMode), mode)) throw new ArgumentException(\"mode must be a defined DenoInspectMode\");","typeGuard":"static bool IsValidInspectMode(DenoInspectMode m) => Enum.IsDefined(m);","tryCatchPattern":"try { resource.WithDenoInspect(mode); } catch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"mode\") { /* fall back to DenoInspectMode.Inspect */ }","preventionTips":["Parse enums with TryParse + IsDefined","Avoid numeric enum literals in configuration","Keep package versions in sync"],"tags":["argument-exception","enum","deno","debugging"],"backgroundTag":"invalid-enum-value","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}