Skip to content

Commit 8046f0c

Browse files
committed
tweak err messages
1 parent 74b11bb commit 8046f0c

File tree

5 files changed

+27
-40
lines changed

5 files changed

+27
-40
lines changed

experimental/api.go

-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ func (b Base64String) String() string {
1919

2020
func GetCommunities() (CommunityList, error) {
2121
res, err := util.JsonGetRequest[CommunitiesResponse]("api/experimental/community")
22-
2322
if err != nil {
2423
return CommunityList{}, err
2524
}
@@ -32,7 +31,6 @@ func GetCommunities() (CommunityList, error) {
3231
// If the name/id does not match any existing community, the result will be nil.
3332
func GetCommunity(nameOrId string) (*Community, bool, error) {
3433
communities, err := GetCommunities()
35-
3634
if err != nil {
3735
return nil, false, err
3836
}

experimental/auth.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type AuthResponse struct {
1111
SessionID string `json:"session_id"`
1212
}
1313

14-
// TODO: Implement this.
15-
func LoginWithGithub(auth AuthOptions) (AuthResponse, error) {
16-
return AuthResponse{}, nil
17-
}
14+
// TODO: Implement this. Edit: forgor why I needed this
15+
// func LoginWithGithub(auth AuthOptions) (AuthResponse, error) {
16+
// return AuthResponse{}, nil
17+
// }

experimental/package.go

-6
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ type Package struct {
2222
Latest PackageVersion `json:"latest"`
2323
}
2424

25-
// region PackageVersion Struct
2625
type PackageVersion struct {
2726
Namespace string `json:"namespace"`
2827
Name string `json:"name"`
@@ -53,9 +52,6 @@ func (pkg PackageVersion) getMarkdown(file string) (common.MarkdownResponse, err
5352
return util.JsonGetRequest[common.MarkdownResponse](endpoint)
5453
}
5554

56-
//endregion
57-
58-
// region ReviewStatus Enum
5955
type ReviewStatus string
6056

6157
const (
@@ -68,8 +64,6 @@ func (rs ReviewStatus) Unreviewed() bool { return rs == UNREVIEWED }
6864
func (rs ReviewStatus) Approved() bool { return rs == APPROVED }
6965
func (rs ReviewStatus) Rejected() bool { return rs == REJECTED }
7066

71-
//endregion
72-
7367
type PackageListing struct {
7468
HasNsfwContent bool `json:"has_nsfw_content"`
7569
Categories string `json:"categories"`

experimental/submission.go

+22-27
Original file line numberDiff line numberDiff line change
@@ -35,74 +35,69 @@ type IconValidatorParams struct {
3535
ImageData []byte
3636
}
3737

38-
func NewErr(msg string) error {
39-
return errors.New(msg)
40-
}
41-
4238
// TODO: Implement this
43-
func SubmitPackage(data []byte) (bool, error) {
44-
return false, nil
45-
}
39+
// func SubmitPackage(data []byte) (bool, error) {
40+
// return false, nil
41+
// }
4642

4743
// TODO: Implement this
48-
func ValidateReadme(data []byte) (bool, error) {
49-
return false, nil
50-
}
44+
// func ValidateReadme(data []byte) (bool, error) {
45+
// return false, nil
46+
// }
5147

52-
func ValidateManifest(author string, data []byte) (bool, []string, error) {
48+
func ValidateManifest(author string, data []byte) (valid bool, errs []string, err error) {
5349
var manifest ManifestMetadata
54-
var errors []string
5550

56-
err := json.Unmarshal(data, &manifest)
51+
err = json.Unmarshal(data, &manifest)
5752
if err != nil {
58-
return false, nil, NewErr("error deserializing manifest: \n" + err.Error())
53+
return false, nil, errors.New("error deserializing manifest: \n" + err.Error())
5954
}
6055

61-
AddIfEmpty(&errors, &manifest.Name, "required property 'name' is empty or unspecified")
62-
AddIfInvalid(&errors, &manifest.Name, "property 'name' must contain only valid characters (a-z A-Z 0-9 _)")
63-
AddIfEmpty(&errors, &manifest.Description, "required property 'description' is empty or unspecified")
56+
AddIfEmpty(&errs, &manifest.Name, "required property 'name' is empty or unspecified")
57+
AddIfInvalid(&errs, &manifest.Name, "property 'name' must contain only valid characters (a-z A-Z 0-9 _)")
58+
AddIfEmpty(&errs, &manifest.Description, "required property 'description' is empty or unspecified")
6459

65-
verEmpty := AddIfEmpty(&errors, &manifest.VersionNumber, "required property 'version_number' is empty or unspecified")
60+
verEmpty := AddIfEmpty(&errs, &manifest.VersionNumber, "required property 'version_number' is empty or unspecified")
6661
if !verEmpty {
67-
valid, _ := util.CheckSemVer(manifest.VersionNumber)
68-
if valid {
62+
matched, _ := util.CheckSemVer(manifest.VersionNumber)
63+
if matched {
6964
pkg, _ := GetPackage(author, manifest.Name)
7065
if pkg != nil {
7166
verA, _ := version.NewSemver(manifest.VersionNumber)
7267
verB, _ := version.NewSemver(pkg.Latest.VersionNumber)
7368

7469
if verA.LessThanOrEqual(verB) {
75-
Add(&errors, "property 'version_number' must be higher than the latest")
70+
Add(&errs, "property 'version_number' must be higher than the latest")
7671
}
7772
}
7873
} else {
79-
Add(&errors, "property 'version_number' does not follow semantic versioning (major.minor.patch)")
74+
Add(&errs, "property 'version_number' does not follow semantic versioning (major.minor.patch)")
8075
}
8176
}
8277

8378
if manifest.WebsiteURL == nil {
84-
Add(&errors, "required property 'website_url' is unspecified")
79+
Add(&errs, "property 'website_url' is empty or unspecified")
8580
} else {
8681
url := strings.ToLower(*manifest.WebsiteURL)
8782
if !(strings.HasPrefix(url, "http://") || strings.HasPrefix(url, "https://")) {
88-
Add(&errors, "property 'website_url' must be a valid URL")
83+
Add(&errs, "property 'website_url' must be a valid URL")
8984
}
9085
}
9186

9287
if manifest.Dependencies == nil {
93-
Add(&errors, "manifest property 'dependencies' is required")
88+
Add(&errs, "required property 'dependencies' is empty or unspecified")
9489
} else {
9590
for _, dep := range manifest.Dependencies {
9691
fullName := author + "-" + manifest.Name
9792
if strings.Contains(strings.ToLower(dep), strings.ToLower(fullName)) {
98-
Add(&errors, "manifest property 'dependencies' is invalid. cannot depend on self")
93+
Add(&errs, "property 'dependencies' is invalid. cannot depend on self")
9994
}
10095

10196
// TODO: Check multiple versions of same package
10297
}
10398
}
10499

105-
return len(errors) < 1, errors, nil
100+
return len(errs) < 1, errs, nil
106101
}
107102

108103
// Decodes image data and validates that the image is a PNG and the dimensions are 256x256.

tests/exp/submission_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func TestValidateIcon(t *testing.T) {
2626
}
2727

2828
func TestValidateManifest(t *testing.T) {
29-
t.Skip()
29+
//t.Skip()
3030

3131
var errs []string
3232

0 commit comments

Comments
 (0)