{"record":{"id":"dc474edd761761d3","repo":"apify/crawlee","slug":"the-urls-parameter-must-be-an-array","errorCode":null,"errorMessage":"The \"urls\" parameter must be an array","messagePattern":"The \"urls\" parameter must be an array","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/utils/src/internals/social.ts","lineNumber":45,"sourceCode":" * @param text Text to search in.\n * @return Array of emails addresses found.\n * If no emails are found, the function returns an empty array.\n */\nexport function emailsFromText(text: string): string[] {\n    if ((typeof text as unknown) !== 'string') return [];\n    return text.match(EMAIL_REGEX_GLOBAL) || [];\n}\n\n/**\n * The function extracts email addresses from a list of URLs.\n * Basically it looks for all `mailto:` URLs and returns valid email addresses from them.\n * Note that the function preserves the order of emails and keep duplicates.\n * @param urls Array of URLs.\n * @return Array of emails addresses found.\n * If no emails are found, the function returns an empty array.\n */\nexport function emailsFromUrls(urls: string[]): string[] {\n    if (!Array.isArray(urls)) throw new Error('The \"urls\" parameter must be an array');\n    const emails: string[] = [];\n\n    for (const url of urls) {\n        if (!url) continue;\n        if (!EMAIL_URL_PREFIX_REGEX.test(url)) continue;\n\n        const email = url.replace(EMAIL_URL_PREFIX_REGEX, '').trim();\n        if (EMAIL_REGEX.test(email)) emails.push(email);\n    }\n\n    return emails;\n}\n\n// Supports URLs starting with `tel://`, `tel:/` and `tel:`, and similarly `phone`, `telephone` and `callto`\nconst PHONE_URL_PREFIX_REGEX = /^(tel|phone|telephone|callto):(\\/)?(\\/)?/i;\n\n// It's pretty much impossible (and unmaintainable) to have just one large regular expression for all possible phone numbers.\n// So here we define various regular expression for typical phone number patterns, which are then used to compile","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/apify/crawlee/blob/dbe57fb09ca607ad59dcf998f3925ef9ac3bb26c/packages/utils/src/internals/social.ts#L27-L63","documentation":"emailsFromUrls expects an array of URL strings and asserts Array.isArray(urls) at entry. Passing anything else (string, object, null, undefined) throws this synchronously as an input contract violation. This is a defensive check to fail fast on wrong argument types.","triggerScenarios":"Calling emailsFromUrls with a single URL string instead of an array (e.g. emailsFromUrls('https://site.com/contact')), or with a non-array value from an untyped/unvalidated code path.","commonSituations":"JavaScript users (no type checking) passing one URL directly; passing an object like { urls: [...] }; passing a result of a function that may return undefined; refactoring from emailsFromString to emailsFromUrls without wrapping the input.","solutions":["Wrap the input in an array: emailsFromUrls([url])","Add a TypeScript type annotation/checked call so tsc catches non-array args","Validate with Array.isArray before calling","Check the upstream producer actually returns an array (log/inspect it)"],"exampleFix":"// before\nconst emails = emailsFromUrls('https://example.com/contact');\n\n// after\nconst emails = emailsFromUrls(['https://example.com/contact']);","handlingStrategy":"type-guard","validationCode":"if (!Array.isArray(urls)) throw new TypeError('emailsFromUrls expects an array of URL strings');\nif (urls.some((u) => typeof u !== 'string')) throw new TypeError('all items must be strings');","typeGuard":"function isStringArray(v: unknown): v is string[] {\n  return Array.isArray(v) && v.every((x) => typeof x === 'string');\n}","tryCatchPattern":"try {\n  emails = emailsFromUrls(input as string[]);\n} catch (err) {\n  if (String(err).includes('must be an array')) emails = emailsFromUrls([String(input)]);\n  else throw err;\n}","preventionTips":["Use TypeScript with string[] typing so this fails at compile time","Wrap single-URL values in arrays before calling extraction helpers","Validate upstream function outputs are arrays before passing them on","Write a unit test covering the single-string mistake"],"tags":["validation","argument-type","email-extraction"],"backgroundTag":"argument-type-mismatch","analyzedSha":"dbe57fb09ca607ad59dcf998f3925ef9ac3bb26c","analyzedAt":"2026-08-30T22:22:28.328Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}