makeplane/plane · error · Error

Invalid URL provided

Error message

Invalid URL provided

What it means

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.

Source

Thrown at packages/utils/src/file.ts:42

 * @param {string} src
 * @returns {string} assetId
 */
export const getAssetIdFromUrl = (src: string): string => {
  // remove the last char if it is a slash
  if (src.charAt(src.length - 1) === "/") src = src.slice(0, -1);
  const sourcePaths = src.split("/");
  const assetUrl = sourcePaths[sourcePaths.length - 1];
  return assetUrl;
};

/**
 * @description encode image via URL to base64
 * @param {string} url
 * @returns
 */
export const getBase64Image = async (url: string): Promise<string> => {
  if (!url || typeof url !== "string") {
    throw new Error("Invalid URL provided");
  }

  // Try to create a URL object to validate the URL
  try {
    new URL(url);
  } catch {
    throw new Error("Invalid URL format");
  }

  const response = await fetch(url);
  // check if the response is OK
  if (!response.ok) {
    throw new Error(`Failed to fetch image: ${response.statusText}`);
  }

  const blob = await response.blob();
  return new Promise((resolve, reject) => {
    const reader = new FileReader();

View on GitHub (pinned to 1c8a60f858)

Solutions

  1. Check the field is a non-empty string before calling (e.g. `if (avatarUrl)`).
  2. Coalesce optional values: `getBase64Image(avatarUrl ?? '')` is wrong; instead guard and skip.
  3. Type the parameter and the source so undefined cannot reach the function at compile time.

Example fix

// before
const b64 = await getBase64Image(user.avatarUrl);

// after
if (typeof user.avatarUrl === 'string' && user.avatarUrl) {
  const b64 = await getBase64Image(user.avatarUrl);
}
Defensive patterns

Strategy: type-guard

Validate before calling

if (typeof url === 'string' && url.trim().length > 0) { await getBase64Image(url); }

Type guard

function isNonEmptyString(u: unknown): u is string { return typeof u === 'string' && u.length > 0; }

Try / catch

try { await getBase64Image(url); } catch (e) { if (/Invalid URL provided/.test((e as Error).message)) { url = DEFAULT_AVATAR_URL; } else throw e; }

Prevention

When it happens

Trigger: Calling getBase64Image(null), getBase64Image(undefined), getBase64Image(''), or getBase64Image(123).

Common situations: 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.

Related errors


AI-assisted analysis of makeplane/plane@1c8a60f858 (2026-08-12). Data as JSON: /api/errors/636c9b75ed186eef. Report an issue: GitHub.