Action

Type

Resolved On

Fix Undefined Variable in CRUD Operations fixing 2026-02-07

Fix Undefined Variable in CRUD Operations

Overview

A critical bug exists in the lib/open.ts and lib/close.ts files where an undefined variable idea is referenced in the goal() functions. This will cause runtime errors when these functions are called.

Problem

In src/lib/open.ts:48

export async function goal(goal: string, owner: string) {
  console.log("Openning Idea: ", idea);  // ❌ 'idea' is not defined
  const { error } = await supabase
    .from("Goals")
    .update({ completed: false })
    .eq("goal", goal)
    .eq("owner", owner);
  // ...
}

In src/lib/close.ts:52

export async function goal(goal: string, owner: string) {
  console.log("Closing Idea: ", idea);  // ❌ 'idea' is not defined
  const { error } = await supabase
    .from("Goals")
    .update({ completed: true })
    .eq("owner", owner)
    .eq("goal", goal);
  // ...
}

Additional Issues

  1. Typo in log message: “Openning” should be “Opening”
  2. Inconsistent log message in close.ts says “Closing Idea” but function is for goals
  3. Parameter name goal shadows the function name goal

Solution

Fix the console.log statements to reference the correct variable:

src/lib/open.ts

export async function goal(goalText: string, owner: string) {
  console.log("Opening Goal: ", goalText);
  const { error } = await supabase
    .from("Goals")
    .update({ completed: false })
    .eq("goal", goalText)
    .eq("owner", owner);
  // ...
}

src/lib/close.ts

export async function goal(goalText: string, owner: string) {
  console.log("Closing Goal: ", goalText);
  const { error } = await supabase
    .from("Goals")
    .update({ completed: true })
    .eq("owner", owner)
    .eq("goal", goalText);
  // ...
}

Impact

This bug will cause a ReferenceError: idea is not defined when:

  • Opening a goal via the API
  • Closing a goal via the API

The error will crash the function execution before the database operation completes.

  • src/lib/open.ts
  • src/lib/close.ts