DEV Community

Cover image for The 8-Hour Debug: How a Silly Mistake Cost Me a Day
mmvergara
mmvergara

Posted on

1 1 1 1 1

The 8-Hour Debug: How a Silly Mistake Cost Me a Day

The Function

function getEnrollmentByStudentIdAndCourseId(
  studentId: string,
  courseId: string
) {
  // fetch logic
  return result;
}
Enter fullscreen mode Exit fullscreen mode

The Mistake

Believe it or not this function caused me a day of debugging. Because of the way I was calling it like this.

const studentId = "ID";
const courseId = "ID";

const enrollment = getEnrollmentByStudentIdAndCourseId(courseId, studentId);
Enter fullscreen mode Exit fullscreen mode

I was passing the arguments in the wrong order. The function signature was getEnrollmentByStudentIdAndCourseId(studentId, courseId) but I was calling it with getEnrollmentByStudentIdAndCourseId(courseId, studentId).

The reason why i took so long debugging it was because function was still returning a result even though the arguments were in the wrong order, but it was the wrong result. I think this is ultimately a mistake i made by writing a bad prisma query that caused it.

The Adjustment

make the argument passing more explicit by using object

type Args = {
  courseId: string;
  studentId: string;
};

function getEnrollmentByStudentIdAndCourseId({ courseId, studentId }: Args) {
  // fetch logic
  return result;
}
Enter fullscreen mode Exit fullscreen mode

Ever since then, when I have a function that takes multiple arguments of the same type like IDs, I started to use object destructuring to make the argument passing more. And also like... made better prisma queries.

I hope this helps you avoid the same mistake I made. Happy coding!

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay