Skip to content

TODO: Handle Error for Existing Branch on Word Submission #52

Open

Description

@babblebey

When a user submits a new word or edits an existing word in the dictionary, the system should check if the branch already exists before attempting to create a new branch. Currently, if a branch with the same name already exists, the submission process fails without providing a clear error message to the user.

https://github.com/babblebey/jargons.dev/blob/0eeb366b4346c28a400586082fadb331c0ee342f/src/lib/branch.js#L10

Proposed Solution:

  1. Add a check in the submission process to verify if the branch already exists. (but this will assume that a fork has already been created before-hand)
  2. If the branch exists, display a user-friendly error message indicating that the word already exists in the dictionary.
  3. Provide guidance on how to proceed, such as editing the existing word instead of creating a new one.

Additional Notes:

  • Important to state that the proposed solution is pretty much me thinking out loud, I have some thought which really looks like it will change how/when we fork in order to address this in the way I am thinking about
  • Its also important to know how/when we fork too, I can shed more lights on this

Activity

  1. FabianEilts commented on Oct 24, 2025

    @FabianEilts
    Contributor

    @babblebey Would like to work on this issue. Could you please assign it to me?

  2. babblebey commented on Oct 24, 2025

    @babblebey
    MemberAuthor

    Hey @FabianEilts,

    This issue has been temporarily addressed though in #66; which fulfils the action of removing the current reference and proceeding to recreating it. That logic is handled here

    /**
    * Temporary workaround for handling deletion of existing reference/branch
    */
    const data = await response.json();
    $isWordSubmitLoading.set(false);
    if (
    response.status === 422 &&
    data.message.includes("Reference already exists")
    ) {
    if (
    confirm(
    "It appears you have an existing reference for the current word, do you wish to clear that reference?",
    )
    ) {
    $isWordSubmitLoading.set(true);
    const response = await fetch("/api/dictionary", {
    method: "DELETE",
    body: formData,
    });
    if (response.status === 200) {
    $isWordSubmitLoading.set(false);
    alert(
    "Reference cleared successfully! Kindly publish your contribution again!",
    );
    }
    } else {
    router.push("/editor");
    }

    Working on this issue would require some thoughts around the current state of the branch....

    • What is the current state of existing branch?
      • is it a Branch for a word contribution that is still pending approval? If it's this, then we'll definitely want to resume the branch to modify pending contribution - and this means we will have to have a jargons Editor resume contribution session - a new session
      • is it a Branch for a word contribution that is approved? If it's this, then we will want to delete, as this might be a branch that wasn't deleted after contribution PR got merged

    ...and a little more thoughts... So I'm curious, how would you approach this?

  3. FabianEilts commented on Oct 25, 2025

    @FabianEilts
    Contributor

    Regarding pending approval:
    Is it possible to offer the user the option to edit the existing word and add a new commit to the PR?

    If a branch for a word contribution is approved, then we can delete it, as you suggested.

    Also found a bug at the current workaround.

    $isWordSubmitLoading.set(true);
    const response = await fetch("/api/dictionary", {
    method: "DELETE",
    body: formData,
    });
    if (response.status === 200) {
    $isWordSubmitLoading.set(false);
    alert(
    "Reference cleared successfully! Kindly publish your contribution again!",
    );
    }

    The condition in Line 176 is always false because the response code of the successful DELETE request is 204. This logic, however, will be rewritten as part of the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions