superRaytin/gitlab-db

better error messaging while creating collections

Closed this issue · 0 comments

detj commented

Problem

If you look at the .createCollection() method, it assumes the error cause is always failure to create a new collection. Additionally, it assumes the user is trying to override existing collection and asks to "use update instead".
There could be multiple different failure causes of RepositoryFiles.create(). The current code doesn't account for those. For example, the GitLab Access Token could have expired, but the user sees the same constant error message. Or say, the GitLab server threw a 5xx error, but the caller would not see a different error message.
This design makes debugging harder. As the only way to know what went wrong is to insert a breakpoint or capture/log the error in the catch block.

Solution

Few ways to better handle these error conditions.

  • Capture & log the error argument in the catch block to better preserve the error cause
  • Rephrase the error message to say "failed to create a new collection". That would be a more accurate description of what is going in these lines of code