{"record":{"id":"a203aa934bd62af7","repo":"makeplane/plane","slug":"invalid-url-format","errorCode":null,"errorMessage":"Invalid URL format","messagePattern":"Invalid URL format","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/utils/src/file.ts","lineNumber":49,"sourceCode":"  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();\n\n    reader.onloadend = () => {\n      if (reader.result) {\n        resolve(reader.result as string);\n      } else {\n        reject(new Error(\"Failed to convert image to base64.\"));\n      }","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/makeplane/plane/blob/1c8a60f858d8472aa56e29994ec1c7926da2c6ce/packages/utils/src/file.ts#L31-L67","documentation":"Second guard in getBase64Image: after confirming url is a non-empty string, the code runs `new URL(url)` to validate the URL syntax. If the constructor throws (malformed URL, missing scheme, invalid characters), this error is raised. Note relative URLs and schemeless hosts will also fail under `new URL`.","triggerScenarios":"getBase64Image('/avatar.png') (relative), getBase64Image('example.com/x.png') (no scheme), getBase64Image('ht!tp://x'), or any string the WHATWG URL parser rejects.","commonSituations":"Passing a relative path that works in <img src> but not in new URL; missing https: prefix; copy-pasted URL with stray characters; data: URLs (valid for new URL but downstream fetch may differ).","solutions":["Ensure the value is an absolute URL with scheme (https://...).","If you have a relative path, resolve it against a base: `new URL(relative, window.location.origin).toString()`.","Prepend 'https://' if the caller commonly omits the scheme."],"exampleFix":"// before\nawait getBase64Image(maybeRelative);\n\n// after\nconst abs = /^https?:\\/\\//.test(maybeRelative)\n  ? maybeRelative\n  : new URL(maybeRelative, window.location.origin).toString();\nawait getBase64Image(abs);","handlingStrategy":"validation","validationCode":"function toAbsoluteUrl(u: string): string | null {\n  try { return new URL(u).toString(); } catch { try { return new URL(u, location.origin).toString(); } catch { return null; } }\n}","typeGuard":"function isAbsoluteUrl(u: string): boolean { try { new URL(u); return true; } catch { return false; } }","tryCatchPattern":"try { await getBase64Image(url); } catch (e) { if (/Invalid URL format/.test((e as Error).message)) { url = toAbsoluteUrl(url) ?? DEFAULT; } else throw e; }","preventionTips":["Always store absolute https URLs","Resolve relative URLs against origin before passing","Reject schemeless values at the form layer"],"tags":["file","validation","url"],"backgroundTag":null,"analyzedSha":"1c8a60f858d8472aa56e29994ec1c7926da2c6ce","analyzedAt":"2026-08-12T14:44:31.636Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}