{"record":{"id":"05e9fe7eb92002da","repo":"remotion-dev/remotion","slug":"could-not-parse-the-serialized-value","errorCode":null,"errorMessage":"Could not parse the serialized value","messagePattern":"Could not parse the serialized value","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/studio-codemods/src/format-serialized-value.ts","lineNumber":46,"sourceCode":"\t\t\t\t? true\n\t\t\t\t: previousValue.startsWith('{') &&\n\t\t\t\t\t  !previousValue.startsWith('{\\n') &&\n\t\t\t\t\t  !previousValue.startsWith('{\\r\\n')\n\t\t\t\t\t? false\n\t\t\t\t\t: inlineObjectSpacing === undefined\n\t\t\t\t\t\t? null\n\t\t\t\t\t\t: inlineObjectSpacing.length > 0;\n\tconst formattingConfig = getSourceFormattingConfig({\n\t\tinput,\n\t\tprettierConfigOverride: bracketSpacing === null ? null : {bracketSpacing},\n\t});\n\tconst valueAst = parseAst(`__value = ${serialized}`);\n\tconst statement = valueAst.program.body[0];\n\tif (\n\t\tstatement?.type !== 'ExpressionStatement' ||\n\t\tstatement.expression.type !== 'AssignmentExpression'\n\t) {\n\t\tthrow new Error('Could not parse the serialized value');\n\t}\n\n\tconst expression = statement.expression.right;\n\trecast.types.visit(expression, {\n\t\tvisitObjectProperty(path) {\n\t\t\tconst {node} = path;\n\t\t\tif (\n\t\t\t\t!node.computed &&\n\t\t\t\tnode.key.type === 'StringLiteral' &&\n\t\t\t\tidentifierRegex.test(node.key.value)\n\t\t\t) {\n\t\t\t\tnode.key = recast.types.builders.identifier(node.key.value);\n\t\t\t}\n\n\t\t\tthis.traverse(path);\n\t\t},\n\t});\n","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/remotion-dev/remotion/blob/46a3a6bf13ca367376ff18bbb06dae2e87e0d068/packages/studio-codemods/src/format-serialized-value.ts#L28-L64","documentation":"formatSerializedValue wraps a serialized value as `__value = <serialized>` and parses it with the Babel parser, expecting an ExpressionStatement containing an AssignmentExpression whose right side is the value. If the string fails to parse or produces a different AST shape, the function cannot extract the value and throws this error.","triggerScenarios":"Passing a string that is not a syntactically valid JS expression literal to formatSerializedValue — e.g. truncated JSON, JSON5/JS-only syntax the parser rejects, or text that parses but is not an assignment-shaped statement.","commonSituations":"Serializing studio props/visual-control values with a custom serializer that emits invalid or truncated output; double-encoding values (JSON string of a string); clipboard-edited values pasted with stray characters.","solutions":["Log and inspect the serialized string; ensure it is a complete, valid JS expression (e.g. JSON.stringify output of an object/array/number).","Re-generate the serialized value from the original data instead of round-tripping a possibly edited string.","Validate with a quick parse check (e.g. JSON.parse for JSON values) before calling formatSerializedValue.","If values are intentionally non-JSON JS literals, ensure they are still parser-valid (quote keys correctly, no trailing commas)."],"exampleFix":"// before (truncated)\nformatSerializedValue('{\"a\": 1, \"b\"'); // throws\n// after\nconst serialized = JSON.stringify({a: 1, b: 2});\nJSON.parse(serialized); // sanity check\nformatSerializedValue(serialized); // ok","handlingStrategy":"validation","validationCode":"function assertSerializable(s: string): string {\n  try { JSON.parse(s); } catch { throw new Error('Serialized value is not valid JSON: ' + s.slice(0, 50)); }\n  return s;\n}\nformatSerializedValue(assertSerializable(serialized));","typeGuard":null,"tryCatchPattern":"try {\n  formatSerializedValue(serialized);\n} catch (e) {\n  if (e instanceof Error && e.message === 'Could not parse the serialized value') {\n    console.error('Bad serialized input:', serialized);\n    serialized = JSON.parse(originalData);\n  } else throw e;\n}","preventionTips":["Only pass JSON.stringify output (or equivalent valid JS literals) to the formatter","Never hand-edit serialized values; regenerate from source data","Sanity-check with JSON.parse before invoking"],"tags":["parse","ast","serialization"],"backgroundTag":"invalid-argument-format","analyzedSha":"46a3a6bf13ca367376ff18bbb06dae2e87e0d068","analyzedAt":"2026-09-18T00:12:20.256Z","contentChangedAt":"2026-09-18T00:12:20.256Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}