{"record":{"id":"73a62d2a3020604a","repo":"microsoft/aspire","slug":"32602-the-export-language-cannot-be-empty","errorCode":"-32602","errorMessage":"The export language cannot be empty.","messagePattern":"The export language cannot be empty\\.","errorType":"exception","errorClass":"LocalRpcException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.RemoteHost/CodeGeneration/CodeGenerationService.cs","lineNumber":303,"sourceCode":"    /// The version label to record for <paramref name=\"packageName\"/>. The caller owns its accuracy;\n    /// see <see cref=\"ApiReferenceExportOptions.PackageVersion\"/>.\n    /// </param>\n    /// <param name=\"cancellationToken\">A token to cancel the export.</param>\n    /// <returns>The language provider's API reference document, verbatim.</returns>\n    [JsonRpcMethod(ExportApiMethodName)]\n    public JsonElement ExportApi(\n        string language,\n        string packageName,\n        string packageVersion,\n        CancellationToken cancellationToken)\n    {\n        using var rpcActivity = _profilingTelemetry.StartJsonRpcServerCall(ExportApiMethodName);\n        try\n        {\n            _authenticationState.ThrowIfNotAuthenticated();\n            if (string.IsNullOrWhiteSpace(language))\n            {\n                throw CreateInvalidExportRequest(\"The export language cannot be empty.\");\n            }\n            if (string.IsNullOrWhiteSpace(packageName))\n            {\n                throw CreateInvalidExportRequest(\"The export package name cannot be empty.\");\n            }\n            if (string.IsNullOrWhiteSpace(packageVersion))\n            {\n                throw CreateInvalidExportRequest(\"The export package version cannot be empty.\");\n            }\n\n            _logger.LogDebug(\">> exportApi({Language}, {PackageName}, {PackageVersion})\", language, packageName, packageVersion);\n            var sw = System.Diagnostics.Stopwatch.StartNew();\n\n            var generator = _resolver.GetCodeGenerator(language);\n            if (generator is null)\n            {\n                throw CreateInvalidExportRequest(BuildNoCodeGeneratorMessage(language));\n            }","sourceCodeStart":285,"sourceCodeEnd":321,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.RemoteHost/CodeGeneration/CodeGenerationService.cs#L285-L321","documentation":"ExportApi validates that the 'language' argument is a non-empty, non-whitespace string before doing any work, throwing an invalid JSON-RPC request error (code -32602) when it is empty. The language selects which registered code generator and exporter will produce the API reference document.","triggerScenarios":"Invoking the JSON-RPC 'exportApi' method with language set to \"\", null-coerced empty, or whitespace (e.g., \" \"), typically because the calling tool passed an unset variable or misread configuration into the language field.","commonSituations":"A CLI or IDE extension reads the target language from config or a command-line flag that was never set; a script template leaves a placeholder like {language} unexpanded to empty; a caller passes the wrong argument positionally so an empty string lands in the language slot.","solutions":["Pass an explicit language name such as \"TypeScript\" in the exportApi request.","Check the config/CLI flag that feeds the language value and ensure it is set before invoking exportApi.","List supported languages (see the resolver's registered code generators) and pick a valid one."],"exampleFix":"// before\nawait rpc.InvokeAsync<JsonElement>(\"exportApi\", new { language = \"\", packageName = \"Aspire.Hosting\", packageVersion = \"9.0.0\" });\n// after\nawait rpc.InvokeAsync<JsonElement>(\"exportApi\", new { language = \"TypeScript\", packageName = \"Aspire.Hosting\", packageVersion = \"9.0.0\" });","handlingStrategy":"validation","validationCode":"if (!language || !language.trim()) {\n  throw new Error('language must be a non-empty string before calling exportApi');\n}","typeGuard":"function isNonEmptyString(v: unknown): v is string {\n  return typeof v === 'string' && v.trim().length > 0;\n}","tryCatchPattern":"try {\n  await rpc.InvokeAsync('exportApi', req);\n} catch (err) {\n  if (err.code === -32602 && err.message.includes('export language cannot be empty')) {\n    req.language = defaultLanguage; // retry with configured default\n  } else throw err;\n}","preventionTips":["Validate all exportApi string arguments (language, packageName, packageVersion) with a non-empty check before invoking.","Read language from a single well-typed config source rather than ad-hoc variables.","Fail fast at script start when required export options are unset.","Use named (not positional) arguments in the JSON-RPC request to avoid slot confusion."],"tags":["json-rpc","validation","code-generation","empty-argument"],"backgroundTag":"empty-required-field","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"}