REST API - Create diff comment thread - fix misleading error message
<!--IssueSummary start--> <details> <summary> Everyone can contribute. [Help move this issue forward](https://handbook.gitlab.com/handbook/marketing/developer-relations/contributor-success/community-contributors-workflows/#contributor-links) while earning points, leveling up and collecting rewards. </summary> - [Close this issue](https://contributors.gitlab.com/manage-issue?action=close&projectId=278964&issueIid=282481) </details> <!--IssueSummary end--> ### 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: https://gitlab.com/viktomas/empty-test-2/-/merge_requests/1/diffs 1. Get the MR version so you can craft the create message request. ```sh curl -H "Authorization: Bearer $TOKEN" 'https://gitlab.com/api/v4/projects/22433161/merge_requests/1/versions' | jq ``` ```json [ { "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" } ] ``` 1. Try to create an MR message, but misspell the file name (the actual filename is `tets-selection.js`) ```sh 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 ``` ```json { "message": "400 (Bad request) \"Note {:line_code=\u003e[\"can't be blank\", \"must be a valid line code\"]}\" not given" } ``` ### Example Project https://gitlab.com/viktomas/empty-test-2/-/merge_requests/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 <!-- Paste any relevant logs - please use code blocks (```) to format console output, logs, and code as it's tough to read otherwise. --> ### Output of checks This bug happens on GitLab.com ### Possible fixes <!-- If you can, link to the line of code that might be responsible for the problem. -->
issue