{"record":{"id":"6811fd7ec722a49d","repo":"BabylonJS/Babylon.js","slug":"consts-must-have-a-value-constline","errorCode":null,"errorMessage":"`Consts must have a value: '${constLine}'`","messagePattern":"`Consts must have a value: '(.+?)'`","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/dev/smartFilters/src/utils/buildTools/shaderConverter.ts","lineNumber":225,"sourceCode":"        const constLine = matches[2];\r\n\r\n        if (!constLine) {\r\n            throw new Error(\"Const line not found\");\r\n        }\r\n\r\n        const constLineMatches = new RegExp(/^const\\s+(\\w+)\\s+(\\w+)\\s*=\\s*([^\\s;]+)\\s*;?\\s*$/gm).exec(constLine);\r\n        if (!constLineMatches || constLineMatches.length < 4) {\r\n            throw new Error(`Consts must have a name, type, and a default value: '${constLine}'`);\r\n        }\r\n        const type = constLineMatches[1];\r\n        const friendlyName = constLineMatches[2];\r\n        const defaultValue = constLineMatches[3];\r\n\r\n        if (!friendlyName) {\r\n            throw new Error(`Consts must have a name: '${constLine}'`);\r\n        }\r\n        if (defaultValue === null) {\r\n            throw new Error(`Consts must have a value: '${constLine}'`);\r\n        }\r\n\r\n        const constProperty: ConstPropertyMetadata | null =\r\n            type === \"float\"\r\n                ? {\r\n                      name: DecorateSymbol(friendlyName),\r\n                      friendlyName,\r\n                      type,\r\n                      defaultValue: parseFloat(defaultValue),\r\n                      options: annotation.property.options as ConstMetadataAnnotationFloatOptions | undefined,\r\n                  }\r\n                : null;\r\n\r\n        if (!constProperty) {\r\n            throw new Error(`Unsupported const property type: '${type}'`);\r\n        }\r\n        fragmentConstProperties.push(constProperty);\r\n\r","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/smartFilters/src/utils/buildTools/shaderConverter.ts#L207-L243","documentation":"The parsed const line has a name but the default-value capture is null. Property consts must carry a default value because it becomes the initial value of the generated Smart Filter property. This is the 'value missing' variant of the const validation errors.","triggerScenarios":"ParseFragmentShader on `const float exposure;` or `const float exposure = ;` — an annotated property const declared without an initializer.","commonSituations":"Declaring a const intending to assign later (invalid for property consts); refactoring removed the initializer; template-generated shader with a missing value placeholder.","solutions":["Add a default value to the const: `const float exposure = 1.0;`.","If no default is desired, remove the {\"property\":...} annotation so the const is treated as ordinary.","Set the default via the annotation's property options if a specific initial value is needed (the defaultValue still must be syntactically present)."],"exampleFix":"// before\n// {\"property\": {\"type\": \"float\"}}\nconst float exposure;\n// after\n// {\"property\": {\"type\": \"float\"}}\nconst float exposure = 1.0;","handlingStrategy":"validation","validationCode":"if (/const\\s+\\w+\\s+\\w+\\s*;/.test(shader)) throw new Error(\"Property consts must declare a default value\");","typeGuard":"function constHasValue(line: string): boolean {\n  const m = /^const\\s+\\w+\\s+\\w+\\s*=\\s*([^\\s;]+)/.exec(line);\n  return !!m && m[1] !== null && m[1].length > 0;\n}","tryCatchPattern":"try {\n  const info = ParseFragmentShader(blockName, namespace, shader);\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith(\"Consts must have a value\")) {\n    // add an initializer to the const and retry\n  } else throw e;\n}","preventionTips":["Always initialize consts at declaration (required by property consts).","If a const is computed at runtime, use a uniform instead of a const.","Grep shader assets for `const \\w+ \\w+;` before building."],"tags":["shader","parsing","glsl","default-value"],"backgroundTag":"shader-const-syntax-invalid","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}