Repository: supabase/supabase
File: apps/studio/components/interfaces/BranchManagement/EditBranchModal.tsx (TypeScript)

Code before:
  const onSubmit = (data: z.infer<typeof FormSchema>) => {
    if (!projectRef) return console.error('Project ref is required')
    if (!branch?.project_ref) return console.error('Branch ref is required')

    const payload: {
      branchRef: string
      projectRef: string
      branchName: string
      gitBranch?: string
    } = {
      branchRef: branch.project_ref,
      projectRef,
      branchName: data.branchName,
    }

    // Only add gitBranch to the payload if it is present and valid
    // If gitBranchName is empty or invalid, gitBranch remains undefined in the payload
    if (data.gitBranchName && isGitBranchValid) {
      payload.gitBranch = data.gitBranchName
    }

    updateBranch(payload)
  }

  const validateGitBranchName = (branchName: string) => {
    if (!githubConnection) return console.error('GitHub Connection is missing')

    const repositoryId = githubConnection.repository.id
    const requested = branchName
    checkGithubBranchValidity(
      { repositoryId, branchName },
      {
        onSuccess: () => {
          if (form.getValues('gitBranchName') !== requested) return
          setIsGitBranchValid(true)
          form.clearErrors('gitBranchName')
        },
        onError: (error) => {
          if (form.getValues('gitBranchName') !== requested) return
          setIsGitBranchValid(false)
          form.setError('gitBranchName', {
            ...error,
            message: `Unable to find branch "${branchName}" in ${repoOwner}/${repoName}`,
          })
        },
      }
    )
  }

  // Pre-fill form when the modal becomes visible and branch data is available
  useEffect(() => {

Review comment (suggestion):
```suggestion
    if (!githubConnection) return console.error('[EditBranchModal > validateGitBranchName] GitHub Connection is missing')
```

These consoles logs go into dashboard logging on support tickets / Sentry errors, so being descriptive will help us pinpoint errors

Code after:
    if (!projectRef) return console.error('Project ref is required')
    if (!branch?.project_ref) return console.error('Branch ref is required')

    const payload: {
      branchRef: string
      projectRef: string
      branchName: string
      gitBranch?: string
    } = {
      branchRef: branch.project_ref,
      projectRef,
      branchName: data.branchName,
    }

    // Only add gitBranch to the payload if it is present and valid
    // If gitBranchName is empty or invalid, gitBranch remains undefined in the payload
    if (data.gitBranchName && isGitBranchValid) {
      payload.gitBranch = data.gitBranchName
    }

    updateBranch(payload)
  }

  const validateGitBranchName = useCallback(
    (branchName: string) => {
      if (!githubConnection)
        return console.error(
          '[EditBranchModal > validateGitBranchName] GitHub Connection is missing'
        )

      const repositoryId = githubConnection.repository.id
      const requested = branchName
      checkGithubBranchValidity(
        { repositoryId, branchName },
        {
          onSuccess: () => {
            if (form.getValues('gitBranchName') !== requested) return
            setIsGitBranchValid(true)
            form.clearErrors('gitBranchName')
          },
          onError: (error) => {
            if (form.getValues('gitBranchName') !== requested) return
            setIsGitBranchValid(false)
            form.setError('gitBranchName', {
              ...error,
              message: `Unable to find branch "${branchName}" in ${repoOwner}/${repoName}`,
            })
          },
        }
      )
    },