Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report errors detail #28

Merged
merged 1 commit into from
Oct 31, 2023
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
38 changes: 34 additions & 4 deletions cmd/diagnose.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,34 @@ type Diagnosis struct {
Ignored bool
Diagnosed bool
IsActive bool
Error error
}

func (d *Diagnosis) ErrorMessage() string {
if d.Error == nil {
return ""
}
return fmt.Sprintf("%s", d.Error)
}

type MedicalTechnician interface {
Libraries(r parser_io.ReadSeekerAt) []types.Library
SourceCodeURL(lib types.Library) (string, error)
}

func FetchRepositoryParams(libs []types.Library, g MedicalTechnician) []github.FetchRepositoryParam {
type RepositoryParams []github.FetchRepositoryParam

func (p RepositoryParams) CanSearchParams() []github.FetchRepositoryParam {
params := []github.FetchRepositoryParam{}
for _, param := range p {
if param.CanSearch {
params = append(params, param)
}
}
return params
}

func FetchRepositoryParams(libs []types.Library, g MedicalTechnician) RepositoryParams {
var params []github.FetchRepositoryParam
var wg sync.WaitGroup
sem := make(chan struct{}, FETCH_REPOS_PER_ONCE)
Expand All @@ -55,6 +75,13 @@ func FetchRepositoryParams(libs []types.Library, g MedicalTechnician) []github.F

url, err := g.SourceCodeURL(lib)
if err != nil {
params = append(params,
github.FetchRepositoryParam{
PackageName: lib.Name,
CanSearch: false,
Error: err,
},
)
return
}

Expand All @@ -64,6 +91,7 @@ func FetchRepositoryParams(libs []types.Library, g MedicalTechnician) []github.F
github.FetchRepositoryParam{
PackageName: lib.Name,
CanSearch: false,
Error: err,
},
)
return
Expand All @@ -90,14 +118,15 @@ func Diagnose(d MedicalTechnician, r io.ReadSeekCloserAt, year int, ignores []st
slicedParams := [][]github.FetchRepositoryParam{}
libs := d.Libraries(r)
fetchRepositoryParams := FetchRepositoryParams(libs, d)
sliceSize := len(fetchRepositoryParams)
canSearchRepositoryParams := fetchRepositoryParams.CanSearchParams()
sliceSize := len(canSearchRepositoryParams)

for i := 0; i < sliceSize; i += github.SEARCH_REPOS_PER_ONCE {
end := i + github.SEARCH_REPOS_PER_ONCE
if sliceSize < end {
end = sliceSize
}
slicedParams = append(slicedParams, fetchRepositoryParams[i:end])
slicedParams = append(slicedParams, canSearchRepositoryParams[i:end])
}

var wg sync.WaitGroup
Expand Down Expand Up @@ -135,6 +164,7 @@ func Diagnose(d MedicalTechnician, r io.ReadSeekCloserAt, year int, ignores []st
diagnosis := Diagnosis{
Name: fetchRepositoryParam.PackageName,
Diagnosed: false,
Error: fetchRepositoryParam.Error,
}
diagnoses[fetchRepositoryParam.PackageName] = diagnosis
}
Expand Down Expand Up @@ -225,7 +255,7 @@ func Report(diagnoses map[string]Diagnosis) error {
}

if !diagnosis.Diagnosed {
warnMessages = append(warnMessages, fmt.Sprintf("[warn] %s (unknown):", diagnosis.Name))
warnMessages = append(warnMessages, fmt.Sprintf("[warn] %s (unknown): %s", diagnosis.Name, diagnosis.ErrorMessage()))
unDiagnosedCount += 1
warnCount += 1
continue
Expand Down
11 changes: 7 additions & 4 deletions cmd/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package github

import (
"context"
"errors"
"fmt"
"log"
"os"
Expand Down Expand Up @@ -39,6 +38,7 @@ type FetchRepositoryParam struct {
Repo string
Owner string
CanSearch bool
Error error
}

func (n FetchRepositoryParam) QueryWord() string {
Expand All @@ -51,12 +51,12 @@ type GitHubURL struct {

func (githuburl GitHubURL) Parse() (string, string, error) {
if githuburl.URL == "" {
return "", "", errors.New("error: Blank URL")
return "", "", fmt.Errorf("source code URL is blank")
}

u, err := giturls.Parse(githuburl.URL)
if err != nil {
return "", "", errors.New("error: Unknown URL")
return "", "", fmt.Errorf("unknown source code URL: %s", githuburl.URL)
}

var owner, repo string
Expand All @@ -66,7 +66,7 @@ func (githuburl GitHubURL) Parse() (string, string, error) {
repo = strings.Replace(paths[1], ".git", "", 1)
} else if u.Scheme == "https" || u.Scheme == "http" {
if len(paths) < 3 {
return "", "", errors.New("error: Unknown URL")
return "", "", fmt.Errorf("unknown source code URL: %s", githuburl.URL)
}
owner = paths[1]
repo = strings.Replace(paths[2], ".git", "", 1)
Expand All @@ -78,7 +78,10 @@ func (githuburl GitHubURL) Parse() (string, string, error) {
owner = paths[3]
repo = strings.Replace(paths[4], ".git", "", 1)
}
} else {
return "", "", fmt.Errorf("unknown source code URL: %s", githuburl.URL)
}

return owner, repo, nil
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/ruby_gems.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ func (g *RubyGems) fetchURLFromRegistry(client http.Client) (string, error) {
return Gem.HomepageUri, nil
}

return "", nil
return "", errors.New("source code URL is not found")
}
Loading