Made error messages a bit more user-friendly

Closes #87
This commit is contained in:
Kir_Antipov 2024-01-14 22:52:08 +03:00
parent 3eb68e07b5
commit 21760b2c91
5 changed files with 13 additions and 10 deletions

View file

@ -50,7 +50,9 @@ export class CurseForgeUploader extends GenericPlatformUploader<CurseForgeUpload
* @inheritdoc
*/
protected async uploadCore(request: CurseForgeUploadRequest): Promise<CurseForgeUploadReport> {
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 });

View file

@ -154,8 +154,8 @@ export abstract class GenericPlatformUploader<TOptions extends GenericPlatformUp
*/
async upload(request: TRequest): Promise<TReport> {
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;

View file

@ -42,12 +42,8 @@ export class GitHubUploader extends GenericPlatformUploader<GitHubUploaderOption
* @param options - The options to use for the uploader.
*/
constructor(options: GitHubUploaderOptions) {
ArgumentNullError.throwIfNull(options, "options");
ArgumentNullError.throwIfNull(options.githubContext, "options.githubContext");
ArgumentNullError.throwIfNull(options.githubContext.repo, "options.githubContext.repo");
super(options);
this._context = options.githubContext;
this._context = options?.githubContext;
}
/**
@ -61,6 +57,8 @@ export class GitHubUploader extends GenericPlatformUploader<GitHubUploaderOption
* @inheritdoc
*/
protected async uploadCore(request: GitHubUploadRequest): Promise<GitHubUploadReport> {
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;

View file

@ -51,7 +51,10 @@ export class ModrinthUploader extends GenericPlatformUploader<ModrinthUploaderOp
* @inheritdoc
*/
protected async uploadCore(request: ModrinthUploadRequest): Promise<ModrinthUploadReport> {
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);

View file

@ -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<T extends McPublishInput[P], P extends PlatformType>(options: T, platform: P, githubContext: GitHubContext, reader?: LoaderMetadataReader): Promise<T> {
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];