From b62df49ca4be30df401907bcc8a9d8310a281c87 Mon Sep 17 00:00:00 2001 From: Jiahao Guo Date: Tue, 24 Sep 2024 15:02:23 +0800 Subject: [PATCH] fix: reject with real errors for GitLab API calls for better debugging In previous implementation, some GitLab API calls would make a Promise rejection with `undefined` as the reason. And in the [global `unhandledRejection` handler](https://github.com/frantic1048/danger-js/blob/b67d710af4d177d57e7091a742da54a2e9fa37fc/source/commands/utils/sharedDangerfileArgs.ts#L5), it will print a generic "Error: undefined" message. This makes debugging very hard. This commit fixes the issue by filling in the rejection reason with the actual error. --- source/platforms/gitlab/GitLabAPI.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/source/platforms/gitlab/GitLabAPI.ts b/source/platforms/gitlab/GitLabAPI.ts index 43a2ce330..34a8f07e6 100644 --- a/source/platforms/gitlab/GitLabAPI.ts +++ b/source/platforms/gitlab/GitLabAPI.ts @@ -184,9 +184,8 @@ class GitLabAPI { return note as Types.MergeRequestNoteSchema } catch (e) { this.d("createMergeRequestNote", e) + throw e } - - return Promise.reject() } updateMergeRequestDiscussionNote = async ( @@ -207,9 +206,8 @@ class GitLabAPI { return discussionNote as Types.MergeRequestDiscussionNoteSchema } catch (e) { this.d("updateMergeRequestDiscussionNote", e) + throw e } - - return Promise.reject() } updateMergeRequestNote = async (id: number, body: string): Promise => { @@ -220,9 +218,8 @@ class GitLabAPI { return note as Types.MergeRequestNoteSchema } catch (e) { this.d("updateMergeRequestNote", e) + throw e } - - return Promise.reject() } // note: deleting the _only_ discussion note in a discussion also deletes the discussion \o/