{"record":{"id":"6e8179bd8177519f","repo":"apple/pkl","slug":"values-of-type-regex-cannot-be-rendered-as-yaml","errorCode":null,"errorMessage":"Values of type `Regex` cannot be rendered as YAML. Value: %s","messagePattern":"Values of type `Regex` cannot be rendered as YAML\\. Value: (.+?)","errorType":"exception","errorClass":"RendererException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/YamlRenderer.java","lineNumber":223,"sourceCode":"              value.getSimpleName()));\n    }\n\n    @Override\n    public void visitTypeAlias(TypeAlias value) {\n      throw new RendererException(\n          String.format(\n              \"Values of type `TypeAlias` cannot be rendered as YAML. Value: %s\",\n              value.getSimpleName()));\n    }\n\n    @Override\n    public void visitNull() {\n      emitter.emit(YamlUtils.plainScalar(\"null\", Tag.NULL));\n    }\n\n    @Override\n    public void visitRegex(Pattern value) {\n      throw new RendererException(\n          String.format(\"Values of type `Regex` cannot be rendered as YAML. Value: %s\", value));\n    }\n\n    private void doVisitIterable(Iterable<?> iterable, @Nullable String tag) {\n      emitter.emit(\n          new SequenceStartEvent(\n              Optional.empty(), Optional.ofNullable(tag), true, FlowStyle.BLOCK));\n      for (var elem : iterable) visit(elem);\n      emitter.emit(new SequenceEndEvent(Optional.empty(), Optional.empty()));\n    }\n\n    private void doVisitProperties(Map<String, ?> properties) {\n      emitter.emit(\n          new MappingStartEvent(Optional.empty(), Optional.empty(), true, FlowStyle.BLOCK));\n\n      for (var entry : properties.entrySet()) {\n        var value = entry.getValue();\n","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/YamlRenderer.java#L205-L241","documentation":"The YAML renderer does not support java.util.regex.Pattern values. Pkl Regex values are patterns, not renderable data, so visitRegex throws a RendererException rather than emitting a guessable representation. The error exists to fail fast instead of silently rendering a misleading string form.","triggerScenarios":"Rendering a property whose value is a Regex (e.g. a property declared as `regex` or produced by Regex(#\"...\")`) via YamlRenderer, or including a Regex-valued member in an object passed to YAML output.","commonSituations":"Validation-heavy configs where pattern properties live next to data properties and a tool renders the whole module to YAML; forgetting to convert a Regex to its .patternString before output.","solutions":["Convert the Regex to a string before rendering (render its pattern source instead of the Pattern object).","Exclude regex/validation properties from the rendered document (e.g. keep them hidden or in a separate non-output module).","If YAML must contain the pattern, wrap it in a String-typed property holding the pattern text."],"exampleFix":"// before (Pkl)\noutput {\n  [\"pattern\"] = myRegex\n}\n// after\noutput {\n  [\"pattern\"] = myRegex.patternString\n}","handlingStrategy":"validation","validationCode":"// before rendering\nif (anyValue is java.util.regex.Pattern || valueIsPklRegex(value)) {\n  throw IllegalArgumentException(\"Convert Regex to its pattern string before YAML rendering\")\n}","typeGuard":"fun isYamlRenderable(v: Any?): Boolean =\n  v !is java.util.regex.Pattern && (v == null || v is String || v is Number || v is Boolean || v is List<*> || v is Map<*, *> || v is org.pkl.core.runtime.VmObject)","tryCatchPattern":null,"preventionTips":["Convert Regex values to pattern strings before output rendering.","Keep validation-only regex properties out of output documents.","Declare output properties as String when they hold pattern text."],"tags":["yaml","renderer","regex","unsupported-operation"],"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"}