{"record":{"id":"96eb70b8aecee8c1","repo":"lovell/sharp","slug":"expected-noise-to-be-an-object","errorCode":null,"errorMessage":"Expected noise to be an object","messagePattern":"Expected noise to be an object","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/input.mjs","lineNumber":353,"sourceCode":"      ) {\n        inputDescriptor.createWidth = inputOptions.create.width;\n        inputDescriptor.createHeight = inputOptions.create.height;\n        inputDescriptor.createChannels = inputOptions.create.channels;\n        inputDescriptor.createPageHeight = 0;\n        if (is.defined(inputOptions.create.pageHeight)) {\n          if (is.integer(inputOptions.create.pageHeight) && inputOptions.create.pageHeight > 0 && inputOptions.create.pageHeight <= inputOptions.create.height) {\n            if (inputOptions.create.height % inputOptions.create.pageHeight !== 0) {\n              throw new Error(`Expected create.height ${inputOptions.create.height} to be a multiple of create.pageHeight ${inputOptions.create.pageHeight}`);\n            }\n            inputDescriptor.createPageHeight = inputOptions.create.pageHeight;\n          } else {\n            throw is.invalidParameterError('create.pageHeight', 'positive integer', inputOptions.create.pageHeight);\n          }\n        }\n        // Noise\n        if (is.defined(inputOptions.create.noise)) {\n          if (!is.object(inputOptions.create.noise)) {\n            throw new Error('Expected noise to be an object');\n          }\n          if (inputOptions.create.noise.type !== 'gaussian') {\n            throw new Error('Only gaussian noise is supported at the moment');\n          }\n          inputDescriptor.createNoiseType = inputOptions.create.noise.type;\n          if (!is.inRange(inputOptions.create.channels, 1, 4)) {\n            throw is.invalidParameterError('create.channels', 'number between 1 and 4', inputOptions.create.channels);\n          }\n          inputDescriptor.createNoiseMean = 128;\n          if (is.defined(inputOptions.create.noise.mean)) {\n            if (is.number(inputOptions.create.noise.mean) && is.inRange(inputOptions.create.noise.mean, 0, 10000)) {\n              inputDescriptor.createNoiseMean = inputOptions.create.noise.mean;\n            } else {\n              throw is.invalidParameterError('create.noise.mean', 'number between 0 and 10000', inputOptions.create.noise.mean);\n            }\n          }\n          inputDescriptor.createNoiseSigma = 30;\n          if (is.defined(inputOptions.create.noise.sigma)) {","sourceCodeStart":335,"sourceCodeEnd":371,"githubUrl":"https://github.com/lovell/sharp/blob/56676c69180a32b468123e090f87bfee30539b49/lib/input.mjs#L335-L371","documentation":"Thrown when inputOptions.create.noise is defined but is not an object. The noise generator requires a descriptor with at least a type field (and optionally mean/sigma), so passing a primitive (number, string, array) is rejected before any field is read. The guard is `!is.object(inputOptions.create.noise)`.","triggerScenarios":"sharp({ create: { width, height, channels, noise: 'gaussian' } }) — a string instead of an object. noise: 5 or noise: ['gaussian']. Mistakenly passing the type directly instead of wrapping it.","commonSituations":"Misreading the API and assuming noise takes a string type. Copying an example that used the old/imagined shorthand. Auto-generating options from a config where noise ended up as a scalar.","solutions":["Wrap the noise spec in an object with a type field: noise: { type: 'gaussian', mean: 128, sigma: 30 }.","Ensure mean and sigma (if provided) are numbers in range 0-10000.","Confirm channels is 1-4 (a separate check inside the noise branch will enforce 1-4)."],"exampleFix":"// before\nsharp({ create: { width: 100, height: 100, channels: 3, noise: 'gaussian' } })\n\n// after\nsharp({ create: { width: 100, height: 100, channels: 3, noise: { type: 'gaussian', mean: 128, sigma: 30 } } })","handlingStrategy":"type-guard","validationCode":"function noiseCreate(opts) {\n  if (typeof opts.noise !== 'object' || opts.noise === null) {\n    throw new Error('create.noise must be an object e.g. { type: \"gaussian\", mean, sigma }');\n  }\n  return sharp({ create: opts });\n}","typeGuard":"function isNoiseObject(v) {\n  return v !== null && typeof v === 'object' && !Array.isArray(v);\n}","tryCatchPattern":null,"preventionTips":["Wrap noise spec as an object, never pass the type string directly.","Use a helper to build the noise descriptor consistently.","Validate the shape before constructing the create object."],"tags":["create","noise","input","validation","type-mismatch"],"backgroundTag":null,"analyzedSha":"56676c69180a32b468123e090f87bfee30539b49","analyzedAt":"2026-08-13T04:44:31.201Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}