{"record":{"id":"636c9b75ed186eef","repo":"makeplane/plane","slug":"invalid-url-provided","errorCode":null,"errorMessage":"Invalid URL provided","messagePattern":"Invalid URL provided","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/utils/src/file.ts","lineNumber":42,"sourceCode":" * @param {string} src\n * @returns {string} assetId\n */\nexport const getAssetIdFromUrl = (src: string): string => {\n  // remove the last char if it is a slash\n  if (src.charAt(src.length - 1) === \"/\") src = src.slice(0, -1);\n  const sourcePaths = src.split(\"/\");\n  const assetUrl = sourcePaths[sourcePaths.length - 1];\n  return assetUrl;\n};\n\n/**\n * @description encode image via URL to base64\n * @param {string} url\n * @returns\n */\nexport const getBase64Image = async (url: string): Promise<string> => {\n  if (!url || typeof url !== \"string\") {\n    throw new Error(\"Invalid URL provided\");\n  }\n\n  // Try to create a URL object to validate the URL\n  try {\n    new URL(url);\n  } catch {\n    throw new Error(\"Invalid URL format\");\n  }\n\n  const response = await fetch(url);\n  // check if the response is OK\n  if (!response.ok) {\n    throw new Error(`Failed to fetch image: ${response.statusText}`);\n  }\n\n  const blob = await response.blob();\n  return new Promise((resolve, reject) => {\n    const reader = new FileReader();","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/makeplane/plane/blob/1c8a60f858d8472aa56e29994ec1c7926da2c6ce/packages/utils/src/file.ts#L24-L60","documentation":"First guard in getBase64Image: the url parameter must be a non-empty string. Anything falsy (null, undefined, '', 0) or not of type string is rejected before any URL parsing or network call. This is a contract check on the caller, not on URL shape.","triggerScenarios":"Calling getBase64Image(null), getBase64Image(undefined), getBase64Image(''), or getBase64Image(123).","commonSituations":"Optional avatar/cover URL field that is empty for the user; destructuring an object whose key is missing; passing a value that was never initialized.","solutions":["Check the field is a non-empty string before calling (e.g. `if (avatarUrl)`).","Coalesce optional values: `getBase64Image(avatarUrl ?? '')` is wrong; instead guard and skip.","Type the parameter and the source so undefined cannot reach the function at compile time."],"exampleFix":"// before\nconst b64 = await getBase64Image(user.avatarUrl);\n\n// after\nif (typeof user.avatarUrl === 'string' && user.avatarUrl) {\n  const b64 = await getBase64Image(user.avatarUrl);\n}","handlingStrategy":"type-guard","validationCode":"if (typeof url === 'string' && url.trim().length > 0) { await getBase64Image(url); }","typeGuard":"function isNonEmptyString(u: unknown): u is string { return typeof u === 'string' && u.length > 0; }","tryCatchPattern":"try { await getBase64Image(url); } catch (e) { if (/Invalid URL provided/.test((e as Error).message)) { url = DEFAULT_AVATAR_URL; } else throw e; }","preventionTips":["Type the source so undefined can't reach here","Guard optional avatar/cover fields at the call site","Default falsy URLs to a fallback before calling"],"tags":["file","validation","url","typescript"],"backgroundTag":null,"analyzedSha":"1c8a60f858d8472aa56e29994ec1c7926da2c6ce","analyzedAt":"2026-08-12T14:44:31.636Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}