[go: up one dir, main page]

Skip to content

REST API - Create diff comment thread - fix misleading error message

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

Summary

My dyslexia cost me a lot of time here.

When we try to submit a comment on an MR diff and we specify incorrect file name, instead of getting a message about non-existent file, we get a message about a missing optional line_code attribute.

This misleads the API user and makes them (me) look for a problem in the wrong place.

Steps to reproduce

  1. Sample project: viktomas/empty-test-2!1 (diffs)

  2. Get the MR version so you can craft the create message request.

    curl -H "Authorization: Bearer $TOKEN" 'https://gitlab.com/api/v4/projects/22433161/merge_requests/1/versions' | jq
    [
      {
        "id": 124423305,
        "head_commit_sha": "943df554d4cc69a63ad43acc9f28bf6a8fa99e48",
        "base_commit_sha": "b62a77777f42dd3bdd0c8f6dcf190ee4581f88a3",
        "start_commit_sha": "b62a77777f42dd3bdd0c8f6dcf190ee4581f88a3",
        "created_at": "2020-11-13T14:29:00.136Z",
        "merge_request_id": 77972283,
        "state": "collected",
        "real_size": "1"
      }
    ]
  3. Try to create an MR message, but misspell the file name (the actual filename is tets-selection.js)

    curl  --request POST --header "Authorization: Bearer $TOKEN" --form "body=Via API" \
    --form "position[old_path]=test-selection.js" --form "position[new_path]=test-selection.js" \
    --form "position[old_line]=20" \
    --form "position[head_sha]=943df554d4cc69a63ad43acc9f28bf6a8fa99e48" \
    --form "position[base_sha]=b62a77777f42dd3bdd0c8f6dcf190ee4581f88a3" \
    --form "position[start_sha]=b62a77777f42dd3bdd0c8f6dcf190ee4581f88a3" \
    --form "position[position_type]=text" \
    https://gitlab.com/api/v4/projects/22433161/merge_requests/1/discussions
    {
        "message": "400 (Bad request) \"Note {:line_code=\u003e[\"can't be blank\", \"must be a valid line code\"]}\" not given"
    }

Example Project

viktomas/empty-test-2!1 (diffs)

What is the current bug behavior?

The error message says that there is a missing line_code attribute.

What is the expected correct behavior?

The error message says that there is no such file.

Relevant logs and/or screenshots

Output of checks

This bug happens on GitLab.com

Possible fixes

Edited by 🤖 GitLab Bot 🤖