{"id":"b47db8d8a5d69bb8","repo":"sindresorhus/is","slug":"expected-value-which-is-non-empty-string-receiv","errorCode":null,"errorMessage":"Expected value which is `non-empty string`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `non-empty string`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1767,"sourceCode":"\t\tthrow new TypeError(message ?? typeErrorMessage('non-empty map', value));\n\t}\n}\n\nexport function assertNonEmptyObject<Key extends keyof any = string, Value = unknown>(value: unknown, message?: string): asserts value is Record<Key, Value> {\n\tif (!isNonEmptyObject(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('non-empty object', value));\n\t}\n}\n\nexport function assertNonEmptySet<T = unknown>(value: unknown, message?: string): asserts value is Set<T> {\n\tif (!isNonEmptySet(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('non-empty set', value));\n\t}\n}\n\nexport function assertNonEmptyString(value: unknown, message?: string): asserts value is string {\n\tif (!isNonEmptyString(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('non-empty string', value));\n\t}\n}\n\nexport function assertNonEmptyStringAndNotWhitespace(value: unknown, message?: string): asserts value is string {\n\tif (!isNonEmptyStringAndNotWhitespace(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('non-empty string and not whitespace', value));\n\t}\n}\n\nexport function assertNonNegativeInteger(value: unknown, message?: string): asserts value is number {\n\tif (!isNonNegativeInteger(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('non-negative integer', value));\n\t}\n}\n\nexport function assertNonNegativeNumber(value: unknown, message?: string): asserts value is number {\n\tif (!isNonNegativeNumber(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('non-negative number', value));","sourceCodeStart":1749,"sourceCodeEnd":1785,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1749-L1785","documentation":"Thrown by `assertNonEmptyString()` (source/index.ts:1765) when the value is not a primitive string with `length > 0`. Both the empty string `''` and non-strings (numbers, `null`, `undefined`, String objects) fail. Note that whitespace-only strings like `' '` pass this check.","triggerScenarios":"Calling `assert.nonEmptyString(value)` with `''`, `undefined`/`null` (unset env var or missing property), a number (e.g. an ID that should have been stringified), or `new String('x')` (object wrapper).","commonSituations":"Missing environment variables (`process.env.FOO` is `undefined` or set to empty in .env/CI); empty form inputs; optional API fields defaulting to `''`; numeric IDs passed where a string is expected.","solutions":["Check the value's source — for env vars, confirm the variable is set and non-empty in the running environment.","Coerce intentionally if appropriate: `String(id)` for numbers.","If empty means 'not provided' and that's valid, guard with `is.nonEmptyString(value)` and handle the absent case explicitly.","If whitespace-only input must also be rejected, use `assert.nonEmptyStringAndNotWhitespace` instead."],"exampleFix":"// before\nconst apiUrl = process.env.API_URL;\nassert.nonEmptyString(apiUrl); // throws: received `undefined`\n// after\nconst apiUrl = process.env.API_URL;\nif (!is.nonEmptyString(apiUrl)) {\n  throw new Error('API_URL environment variable must be set to a non-empty URL');\n}","handlingStrategy":"type-guard","validationCode":"if (typeof value === 'string' && value.length > 0) {\n  assert.nonEmptyString(value);\n}","typeGuard":"function isNonEmptyString(v: unknown): v is string {\n  return typeof v === 'string' && v.length > 0;\n}","tryCatchPattern":"try {\n  assert.nonEmptyString(name);\n} catch (error) {\n  if (error instanceof TypeError) {\n    // name is '', null, undefined, or non-string — reject the input with a clear message\n  }\n  throw error;\n}","preventionTips":["Guard with is.nonEmptyString(value) at input boundaries (env vars, form fields, URL params) where '' is common","Never coerce with String(value) first — that turns undefined into 'undefined' and hides the real bug","Beware that '' is falsy: value || fallback patterns can mask where the empty string came from; validate early instead"],"tags":["assertion","type-check","string","environment","typescript"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}