{"record":{"id":"80efa9651656c929","repo":"lovell/sharp","slug":"expected-a-valid-string-to-create-an-image-with-te","errorCode":null,"errorMessage":"Expected a valid string to create an image with text.","messagePattern":"Expected a valid string to create an image with text\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/input.mjs","lineNumber":470,"sourceCode":"          }\n        }\n        if (is.defined(inputOptions.text.spacing)) {\n          if (is.integer(inputOptions.text.spacing) && is.inRange(inputOptions.text.spacing, -1000000, 1000000)) {\n            inputDescriptor.textSpacing = inputOptions.text.spacing;\n          } else {\n            throw is.invalidParameterError('text.spacing', 'integer between -1000000 and 1000000', inputOptions.text.spacing);\n          }\n        }\n        if (is.defined(inputOptions.text.wrap)) {\n          if (is.string(inputOptions.text.wrap) && is.inArray(inputOptions.text.wrap, ['word', 'char', 'word-char', 'none'])) {\n            inputDescriptor.textWrap = inputOptions.text.wrap;\n          } else {\n            throw is.invalidParameterError('text.wrap', 'one of: word, char, word-char, none', inputOptions.text.wrap);\n          }\n        }\n        delete inputDescriptor.buffer;\n      } else {\n        throw new Error('Expected a valid string to create an image with text.');\n      }\n    }\n    // Join images together\n    if (is.defined(inputOptions.join)) {\n      if (is.defined(this.options.join)) {\n        if (is.defined(inputOptions.join.animated)) {\n          if (is.bool(inputOptions.join.animated)) {\n            inputDescriptor.joinAnimated = inputOptions.join.animated;\n          } else {\n            throw is.invalidParameterError('join.animated', 'boolean', inputOptions.join.animated);\n          }\n        }\n        if (is.defined(inputOptions.join.across)) {\n          if (is.integer(inputOptions.join.across) && is.inRange(inputOptions.join.across, 1, 1000000)) {\n            inputDescriptor.joinAcross = inputOptions.join.across;\n          } else {\n            throw is.invalidParameterError('join.across', 'integer between 1 and 100000', inputOptions.join.across);\n          }","sourceCodeStart":452,"sourceCodeEnd":488,"githubUrl":"https://github.com/lovell/sharp/blob/56676c69180a32b468123e090f87bfee30539b49/lib/input.mjs#L452-L488","documentation":"Thrown when inputOptions.text is provided but text.text is not a string (or text itself is not an object with a string text field). The text renderer needs the actual string content to rasterize, so missing/non-string content cannot proceed. This is the else branch after `is.object(text) && is.string(text.text)`.","triggerScenarios":"sharp({ text: { text: 123 } }), sharp({ text: { text: null } }), sharp({ text: {} }) with no text field, or sharp({ text: 'hello' }) passing the string directly instead of wrapping it.","commonSituations":"Passing the string at the wrong level (sharp({ text: 'hello' }) instead of sharp({ text: { text: 'hello' } })). Forgetting to set the content when building the object programmatically. Receiving text from a non-string source (number id, object) without coercion.","solutions":["Wrap the string: sharp({ text: { text: 'hello' } }).","Coerce non-strings: text: { text: String(value) }.","Guard that the content is a non-empty string before calling sharp."],"exampleFix":"// before\nsharp({ text: 'hello' })\n\n// after\nsharp({ text: { text: 'hello' } })","handlingStrategy":"type-guard","validationCode":"function textCreate(content, opts = {}) {\n  if (typeof content !== 'string') {\n    throw new Error('text.text must be a non-empty string');\n  }\n  return sharp({ text: { text: content, ...opts } });\n}","typeGuard":"function isTextSpec(text) {\n  return text !== null && typeof text === 'object' && typeof text.text === 'string';\n}","tryCatchPattern":null,"preventionTips":["Wrap text content at { text: '...' } not at the top level.","Coerce non-strings with String() before assigning to text.text.","Validate the content is a non-empty string for meaningful output."],"tags":["text","input","validation","type-mismatch"],"backgroundTag":null,"analyzedSha":"56676c69180a32b468123e090f87bfee30539b49","analyzedAt":"2026-08-13T04:44:31.201Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}