From 21760b2c91945bad04dadf987005db3c421941c9 Mon Sep 17 00:00:00 2001 From: Kir_Antipov Date: Sun, 14 Jan 2024 22:52:08 +0300 Subject: [PATCH] Made error messages a bit more user-friendly Closes #87 --- src/platforms/curseforge/curseforge-uploader.ts | 4 +++- src/platforms/generic-platform-uploader.ts | 4 ++-- src/platforms/github/github-uploader.ts | 8 +++----- src/platforms/modrinth/modrinth-uploader.ts | 5 ++++- src/program.ts | 2 +- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/platforms/curseforge/curseforge-uploader.ts b/src/platforms/curseforge/curseforge-uploader.ts index 1af6c14..bacc104 100644 --- a/src/platforms/curseforge/curseforge-uploader.ts +++ b/src/platforms/curseforge/curseforge-uploader.ts @@ -50,7 +50,9 @@ export class CurseForgeUploader extends GenericPlatformUploader { - ArgumentError.throwIfNullOrEmpty(request.id, "request.id"); + ArgumentError.throwIfNullOrEmpty(request.id, "request.id", "A project ID is required to upload files to CurseForge."); + ArgumentError.throwIfNullOrEmpty(request.loaders, "request.loaders", "At least one loader should be specified to upload files to CurseForge."); + ArgumentError.throwIfNullOrEmpty(request.gameVersions, "request.gameVersions", "At least one game version should be specified to upload files to CurseForge."); const api = new CurseForgeUploadApiClient({ token: request.token.unwrap(), fetch: this._fetch }); const eternalApi = new CurseForgeEternalApiClient({ fetch: this._fetch }); diff --git a/src/platforms/generic-platform-uploader.ts b/src/platforms/generic-platform-uploader.ts index 7cfb838..566cbcd 100644 --- a/src/platforms/generic-platform-uploader.ts +++ b/src/platforms/generic-platform-uploader.ts @@ -154,8 +154,8 @@ export abstract class GenericPlatformUploader { ArgumentNullError.throwIfNull(request, "request"); - ArgumentNullError.throwIfNull(request.token, "request.token"); - ArgumentNullError.throwIfNullOrEmpty(request.files, "request.files"); + ArgumentNullError.throwIfNull(request.token, "request.token", `A token is required to upload files to ${PlatformType.friendlyNameOf(this.platform)}.`); + ArgumentNullError.throwIfNullOrEmpty(request.files, "request.files", "No files to upload were specified. Please include at least one file in the request."); const platformName = PlatformType.friendlyNameOf(this.platform); const maxAttempts = request.retryAttempts ?? DEFAULT_RETRY_ATTEMPTS; diff --git a/src/platforms/github/github-uploader.ts b/src/platforms/github/github-uploader.ts index b45fac5..e5f31d1 100644 --- a/src/platforms/github/github-uploader.ts +++ b/src/platforms/github/github-uploader.ts @@ -42,12 +42,8 @@ export class GitHubUploader extends GenericPlatformUploader { + ArgumentNullError.throwIfNull(this._context?.repo, "context.repo", "The information about the repository is required to upload files to GitHub."); + const api = new GitHubApiClient({ token: request.token.unwrap(), fetch: this._fetch, baseUrl: this._context.apiUrl }); const repo = this._context.repo; diff --git a/src/platforms/modrinth/modrinth-uploader.ts b/src/platforms/modrinth/modrinth-uploader.ts index c3a8792..a7ed79a 100644 --- a/src/platforms/modrinth/modrinth-uploader.ts +++ b/src/platforms/modrinth/modrinth-uploader.ts @@ -51,7 +51,10 @@ export class ModrinthUploader extends GenericPlatformUploader { - ArgumentError.throwIfNullOrEmpty(request.id, "request.id"); + ArgumentError.throwIfNullOrEmpty(request.id, "request.id", "A project ID is required to upload files to Modrinth."); + ArgumentError.throwIfNullOrEmpty(request.version, "request.version", "A version number is required to upload files to Modrinth."); + ArgumentError.throwIfNullOrEmpty(request.loaders, "request.loaders", "At least one loader should be specified to upload files to Modrinth."); + ArgumentError.throwIfNullOrEmpty(request.gameVersions, "request.gameVersions", "At least one game version should be specified to upload files to Modrinth."); const api = new ModrinthApiClient({ token: request.token.unwrap(), fetch: this._fetch }); const unfeatureMode = request.unfeatureMode ?? (request.featured ? ModrinthUnfeatureMode.SUBSET : ModrinthUnfeatureMode.NONE); diff --git a/src/program.ts b/src/program.ts index 4dcc1b6..a3a1b62 100644 --- a/src/program.ts +++ b/src/program.ts @@ -99,7 +99,7 @@ async function publish(action: Action, githubContext: GitHubContext, logger: Log * @returns A promise that resolves to the options with default values filled in. */ async function fillInDefaultValues(options: T, platform: P, githubContext: GitHubContext, reader?: LoaderMetadataReader): Promise { - ArgumentError.throwIfNullOrEmpty(options.files, "options.files"); + ArgumentError.throwIfNullOrEmpty(options.files, "options.files", "No files found for the specified glob. Please ensure the glob is correct and files matching the pattern exist in the specified directory."); options = { ...options }; const primaryFile = options.files[0];