Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Make our validation errors more specific #3053

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/ApiService/ApiService/OneFuzzTypes/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public enum ErrorCode {
UNABLE_TO_DOWNLOAD_FILE = 475,
VM_UPDATE_FAILED = 476,
UNSUPPORTED_FIELD_OPERATION = 477,
ADO_VALIDATION_INVALID_PAT = 478,
ADO_VALIDATION_INVALID_FIELDS = 479,
GITHUB_VALIDATION_INVALID_PAT = 480,
GITHUB_VALIDATION_INVALID_REPOSITORY = 481,
}

public enum VmState {
Expand Down
8 changes: 4 additions & 4 deletions src/ApiService/ApiService/onefuzzlib/notifications/Ado.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ public static async Async.Task<OneFuzzResultVoid> Validate(AdoTemplate config) {
connection = new VssConnection(config.BaseUrl, new VssBasicCredential(string.Empty, token.Value));
await connection.ConnectAsync();
} catch {
return OneFuzzResultVoid.Error(ErrorCode.INVALID_CONFIGURATION, $"Failed to connect to {config.BaseUrl} using the provided token");
return OneFuzzResultVoid.Error(ErrorCode.ADO_VALIDATION_INVALID_PAT, $"Failed to connect to {config.BaseUrl} using the provided token");
}
} else {
return OneFuzzResultVoid.Error(ErrorCode.INVALID_CONFIGURATION, "Auth token is missing or invalid");
return OneFuzzResultVoid.Error(ErrorCode.ADO_VALIDATION_INVALID_PAT, "Auth token is missing or invalid");
}

try {
Expand All @@ -91,15 +91,15 @@ public static async Async.Task<OneFuzzResultVoid> Validate(AdoTemplate config) {

if (!validConfigFields.SetEquals(configFields)) {
var invalidFields = configFields.Except(validConfigFields);
return OneFuzzResultVoid.Error(ErrorCode.INVALID_CONFIGURATION, new[]
return OneFuzzResultVoid.Error(ErrorCode.ADO_VALIDATION_INVALID_FIELDS, new[]
{
$"The following unique fields are not valid fields for this project: {string.Join(',', invalidFields)}",
"You can find the valid fields for your project by following these steps: https://learn.microsoft.com/en-us/azure/devops/boards/work-items/work-item-fields?view=azure-devops#review-fields"
}
);
}
} catch {
return OneFuzzResultVoid.Error(ErrorCode.INVALID_CONFIGURATION, "Failed to query and compare the valid fields for this project");
return OneFuzzResultVoid.Error(ErrorCode.ADO_VALIDATION_INVALID_FIELDS, "Failed to query and compare the valid fields for this project");
}

return OneFuzzResultVoid.Ok;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ public static async Async.Task<OneFuzzResultVoid> Validate(GithubIssuesTemplate
gh = GetGitHubClient(auth.Value.User, auth.Value.PersonalAccessToken);
var _ = await gh.User.Get(auth.Value.User);
} catch {
return OneFuzzResultVoid.Error(ErrorCode.INVALID_CONFIGURATION, $"Failed to login to github.com with user {auth.Value.User} and the provided Personal Access Token");
return OneFuzzResultVoid.Error(ErrorCode.GITHUB_VALIDATION_INVALID_PAT, $"Failed to login to github.com with user {auth.Value.User} and the provided Personal Access Token");
}
} else {
return OneFuzzResultVoid.Error(ErrorCode.INVALID_CONFIGURATION, $"GithubAuth is missing or invalid");
return OneFuzzResultVoid.Error(ErrorCode.GITHUB_VALIDATION_INVALID_PAT, $"GithubAuth is missing or invalid");
}

try {
var _ = await gh.Repository.Get(config.Organization, config.Repository);
} catch {
return OneFuzzResultVoid.Error(ErrorCode.INVALID_CONFIGURATION, $"Failed to access repository: {config.Organization}/{config.Repository}");
return OneFuzzResultVoid.Error(ErrorCode.GITHUB_VALIDATION_INVALID_REPOSITORY, $"Failed to access repository: {config.Organization}/{config.Repository}");
}

return OneFuzzResultVoid.Ok;
Expand Down