{"record":{"id":"4906b9460ea362c1","repo":"gatsbyjs/gatsby","slug":"prop-has-to-be-a-positive-int-larger-than-zero","errorCode":null,"errorMessage":"${prop} has to be a positive int larger than zero (> 0), now it's ${options[prop]}","messagePattern":"(.+?) has to be a positive int larger than zero \\(> 0\\), now it's (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/gatsby-plugin-sharp/src/plugin-options.ts","lineNumber":223,"sourceCode":"  if (options.height !== undefined) {\n    // @ts-ignore - parseInt as safeguard, expects string tho\n    options.height = parseInt(options.height, 10)\n  }\n\n  // only set maxWidth to 800 if neither maxWidth nor maxHeight is passed\n  if (options.maxWidth === undefined && options.maxHeight === undefined) {\n    options.maxWidth = 800\n  } else if (options.maxWidth !== undefined) {\n    // @ts-ignore - parseInt as safeguard, expects string tho\n    options.maxWidth = parseInt(options.maxWidth, 10)\n  } else if (options.maxHeight !== undefined) {\n    // @ts-ignore - parseInt as safeguard, expects string tho\n    options.maxHeight = parseInt(options.maxHeight, 10)\n  }\n\n  ;[`width`, `height`, `maxWidth`, `maxHeight`].forEach(prop => {\n    if (typeof options[prop] !== `undefined` && options[prop] < 1) {\n      throw new Error(\n        `${prop} has to be a positive int larger than zero (> 0), now it's ${options[prop]}`\n      )\n    }\n  })\n  return options\n}\n\n/**\n * Removes all default values so we have the smallest transform args\n */\nexport const removeDefaultValues = (\n  args: ITransformArgs,\n  pluginOptions: ISharpPluginOptions\n): Partial<ITransformArgs> => {\n  const options = {\n    height: args.height,\n    width: args.width,\n    cropFocus: args.cropFocus,","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/gatsby-plugin-sharp/src/plugin-options.ts#L205-L241","documentation":"healOptions validates each of width, height, maxWidth, maxHeight: if defined and < 1, it throws. This is the options-level guard (called before the resize pipeline) and complements the runtime check in index.js. It catches 0, negatives, and NaN (since NaN < 1 is false, NaN slips through this guard - the real protection is the parseInt producing NaN leading to a downstream sharp error, but numeric <1 values throw here).","triggerScenarios":"Passing width={0}, height={-50}, maxWidth={0}, or maxHeight={-1} to a sharp transform or gatsby-image/StaticImage.","commonSituations":"Hard-coded placeholders left at 0; computed dimensions from layout math that underflow; CMS fields storing 0 as 'unknown'; unit mismatches producing tiny or negative numbers.","solutions":["Pass only positive numbers for width/height/maxWidth/maxHeight.","Validate and clamp before calling: Math.max(1, value) for each.","If a dimension is genuinely unknown, omit it (undefined is allowed and skipped)."],"exampleFix":"// before\nsharp({ file, args: { width: 0, height: 600 } })\n\n// after\nsharp({ file, args: { width: 800, height: 600 } })","handlingStrategy":"validation","validationCode":"function assertPositiveDimensions(options) {\n  ['width', 'height', 'maxWidth', 'maxHeight'].forEach(prop => {\n    if (options[prop] !== undefined && !(Number(options[prop]) >= 1)) {\n      throw new Error(`${prop} must be >= 1, got ${options[prop]}`);\n    }\n  });\n}","typeGuard":"function hasValidDimensions(options) {\n  return ['width', 'height', 'maxWidth', 'maxHeight'].every(prop =>\n    options[prop] === undefined || Number(options[prop]) >= 1\n  );\n}","tryCatchPattern":null,"preventionTips":["Type image option props strictly (number, not string).","Coerce and clamp user-supplied sizes before passing to sharp.","Leave dimensions undefined rather than 0 when unknown."],"tags":["gatsby-plugin-sharp","image-processing","validation","dimensions"],"backgroundTag":null,"analyzedSha":"8b06340921ffdf23125a365b9c9923690cb62ce6","analyzedAt":"2026-08-13T02:36:21.405Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}