{"record":{"id":"7f073a1f52a549b4","repo":"apple/pkl","slug":"cannotrendervalue","errorCode":"cannotRenderValue","errorMessage":"cannotRenderValue","messagePattern":"cannotRenderValue","errorType":"error_code","errorClass":"VmException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/stdlib/base/JsonRendererNodes.java","lineNumber":96,"sourceCode":"    }\n\n    /** Use same escaping strategy as {@link org.pkl.core.util.json.JsonWriter}. */\n    @Override\n    public void visitString(String value) {\n      builder.append('\"');\n      escaper.escape(value, builder);\n      builder.append('\"');\n    }\n\n    @Override\n    public void visitInt(Long value) {\n      builder.append((long) value);\n    }\n\n    @Override\n    public void visitFloat(Double value) {\n      if (value.isNaN() || value.isInfinite()) {\n        throw new VmExceptionBuilder().evalError(\"cannotRenderValue\", value, name).build();\n      }\n      builder.append((double) value);\n    }\n\n    @Override\n    public void visitBoolean(Boolean value) {\n      builder.append((boolean) value);\n    }\n\n    @Override\n    public void visitNull(VmNull value) {\n      builder.append(\"null\");\n    }\n\n    @Override\n    public void visitRenderDirective(VmTyped value) {\n      // append verbatim\n      builder.append(VmUtils.readTextProperty(value));","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/stdlib/base/JsonRendererNodes.java#L78-L114","documentation":"JSON has no representation for NaN or Infinity, so JsonRendererNodes' visitFloat throws cannotRenderValue when a Double value being rendered is NaN or infinite. The offending value and renderer name are attached to the error. All other floats render normally as JSON numbers.","triggerScenarios":"Rendering output as JSON (JsonRenderer) where any reachable value is a Double equal to NaN, POSITIVE_INFINITY, or NEGATIVE_INFINITY — typically the result of 0.0/0.0, sqrt(-1) style math, or divide-by-zero on floats.","commonSituations":"Computing metrics or ratios in Pkl that divide by zero; importing data containing NaN from calculations; converting scientific/numeric configs where a sentinel infinity crept in.","solutions":["Fix the computation producing NaN/Infinity (check for division by zero or invalid inputs).","Replace NaN/Infinity values with a JSON-safe sentinel such as null or a string (e.g. `\"Infinity\"`) before rendering.","Guard with `value.isNaN || value.isInfinite` and substitute a default.","Render with a different format (e.g. YAML, which supports .inf/.nan) if the values are intentional."],"exampleFix":"// before\noutput { ratio = 1.0 / 0.0 } // Infinity -> cannotRenderValue\n\n// after\noutput { ratio = if (denom == 0.0) null else numer / denom }","handlingStrategy":"validation","validationCode":"// replace non-JSON-safe floats before rendering\nfunction jsonSafe(v: Number) = if (v.isNaN || v.isInfinite) null else v","typeGuard":"function isJsonSafeFloat(v) { return Number.isFinite(v); }","tryCatchPattern":"try { renderJson(value) } catch (e) { if (e.message.contains('cannotRenderValue')) renderJson(sanitizeFloats(value)) else throw e }","preventionTips":["Check divisions for zero denominators","Sanitize computed floats before output","Prefer YAML output when NaN/Infinity values are intentional"],"tags":["pkl","json","renderer","float","nan"],"backgroundTag":"invalid-argument-value","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}