{"record":{"id":"95e3f694b233abb8","repo":"apple/pkl","slug":"cannotrenderprotobufmapkeytype","errorCode":"cannotRenderProtobufMapKeyType","errorMessage":"cannotRenderProtobufMapKeyType","messagePattern":"cannotRenderProtobufMapKeyType","errorType":"error_code","errorClass":"VmException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/stdlib/protobuf/RendererNodes.java","lineNumber":600,"sourceCode":"        return resolveType(nullableType.getElementTypeNode());\n      } else if (type instanceof TypeAliasTypeNode typeAliasType) {\n        return resolveType(typeAliasType.getVmTypeAlias().getTypeNode());\n      } else if (type instanceof ListingTypeNode listingType) {\n        var valueType = resolveType(listingType.getValueTypeNode());\n        assert valueType != null : \"Failed to resolve type node.\";\n\n        type =\n            requiresWrapper()\n                ? null\n                : new ListingTypeNode(\n                    VmUtils.unavailableSourceSection(), VmLanguage.get(null), valueType);\n        return type;\n      } else if (type instanceof MappingTypeNode mappingType) {\n        var keyType = resolveType(mappingType.getKeyTypeNode());\n        if (!(keyType instanceof IntTypeNode\n            || keyType instanceof StringTypeNode\n            || keyType instanceof BooleanTypeNode)) {\n          throw new VmExceptionBuilder()\n              .evalError(\"cannotRenderProtobufMapKeyType\")\n              .withSourceSection(type.getSourceSection())\n              .build();\n        }\n        var valueType = resolveType(mappingType.getValueTypeNode());\n        assert valueType != null : \"Incomplete or malformed Mapping type\";\n        mappingType =\n            new MappingTypeNode(\n                VmUtils.unavailableSourceSection(), VmLanguage.get(null), keyType, valueType);\n\n        type = requiresWrapper() ? null : mappingType;\n        return type;\n      } else if (type instanceof UnionTypeNode) {\n        // Some non-obvious normalization going on here:\n        // - A union type resolves to a union type, unless all element types are string or string\n        // literal types.\n        // - All element types are resolved also.\n        // - All string literal types are combined into a single String case.","sourceCodeStart":582,"sourceCodeEnd":618,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/stdlib/protobuf/RendererNodes.java#L582-L618","documentation":"Protobuf map keys can only be integral, string, or boolean types. When the renderer resolves a `Mapping` type whose key type resolves to anything else (e.g. Int8/UInt16, DataSize, enum, or class types), it throws this error.","triggerScenarios":"Rendering a `Mapping<K, V>` to Protobuf where K resolves to a type other than Int, String, or Boolean, e.g. `Mapping<Int128, String>` or a Listing/enum-keyed mapping.","commonSituations":"Maps keyed by enums, custom key classes, or wide integer types (Int8, UInt, Float) exported to protobuf.","solutions":["Change the map key type to `String` (most compatible) and encode structured keys as strings","Use `Int` or `Boolean` keys if semantically appropriate","Render to JSON/YAML instead of Protobuf, which allows arbitrary keys","Pre-process the mapping into a Listing of entries with `key`/`value` properties"],"exampleFix":"// before\nports: Mapping<Int16, String>\n// after\nports: Mapping<String, String>  // keys as strings, e.g. \"8080\" -> \"http\"","handlingStrategy":"validation","validationCode":"function hasProtobufSafeKeys(m: Mapping): Boolean =\n  m.keys.every((k) -> k is String || k is Int || k is Boolean)","typeGuard":"function protobufSafeMap(m: Mapping): Boolean = m.keys.every((k) -> k is String || k is Int || k is Boolean)","tryCatchPattern":null,"preventionTips":["Key mappings with String (or Int/Boolean) only","Convert enum/class keys to strings before rendering","Encode structured keys (e.g. tuples) into a single string key"],"tags":["protobuf","map","key-type","pkl"],"backgroundTag":"unsupported-operation","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}