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

Standardize errors #259

Merged
merged 7 commits into from
Nov 29, 2022
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
6 changes: 4 additions & 2 deletions .github/ISSUE_TEMPLATE/bug-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ assignees: nitro-neal, decentralgabe

**To Reproduce**
*Steps to reproduce the behavior:*

1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
Expand All @@ -24,8 +25,9 @@ assignees: nitro-neal, decentralgabe
*If applicable, add screenshots and/or other documentation to help explain your problem.*

**Environment (please complete the following information):**
- OS: [e.g. iOS]
- Version [e.g. 22]

- OS: [e.g. iOS]
- Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
1 change: 0 additions & 1 deletion .github/ISSUE_TEMPLATE/idea-submission.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ assignees: decentralgabe, nitro-neal
**Describe alternatives you've considered**
*A clear and concise description of any alternative solutions or features you've considered.*


**Getting it done**
*Are you building this yourself? Do you need help? What is the urgency of the feature? What are the next steps?*

Expand Down
9 changes: 7 additions & 2 deletions .github/PULL_REQUEST_TEMPLATE/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# Overview

_Include a summary of the change and link to the issue it addresses._

# Description

_Include context, motivation, brief description, and an impact of the change(s). List follow-up tasks here._

# How Has This Been Tested?

_Describe the tests that you ran to verify your changes. Provide instructions for verification._

- [ ] Test A (e.g. Test A - New test that does ... run in ...)
Expand All @@ -15,9 +18,11 @@ _Describe the tests that you ran to verify your changes. Provide instructions fo
Before submitting this PR, please make sure:

- [ ] I have read the CONTRIBUTING document.
- [ ] My code is consistent with the rest of the project
- [ ] My code is consistent with the rest of the project
- [ ] I have tagged the relevant reviewers and/or interested parties
- [ ] I have updated the READMEs and other documentation of affected packages

## References
_Please list relevant documentation (e.g. tech specs, articles, follow up or related work) relevant to this change, and note if the documentation has been updated._

_Please list relevant documentation (e.g. tech specs, articles, follow up or related work) relevant to this change, and
note if the documentation has been updated._
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ on:
workflow_dispatch:

jobs:
vulnerability-scan:
vulnerability-scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -29,7 +29,7 @@ jobs:
run: go install github.com/magefile/mage

- name: Check Vulnerabilities
run: mage -v vuln
run: mage -v vuln
build:
runs-on: ubuntu-latest
steps:
Expand All @@ -42,7 +42,7 @@ jobs:

- name: Install Mage
run: go install github.com/magefile/mage

- name: Build
run: mage build

Expand Down
5 changes: 3 additions & 2 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ linters-settings:
- name: banned-characters
severity: warning
disabled: false
arguments: [ "Ω", "Σ", "σ"]
arguments: [ "Ω", "Σ", "σ" ]
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#bare-return
- name: bare-return
severity: warning
Expand Down Expand Up @@ -69,7 +69,8 @@ linters-settings:
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#context-as-argument
- name: context-as-argument
severity: warning
disabled: false
# # TODO re-enable linter when it isn't broken https://github.com/golangci/golangci-lint/issues/3280
disabled: true
arguments:
- allowTypesBefore: "*testing.T,*github.com/user/repo/testing.Harness"
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#context-keys-type
Expand Down
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ We advocate an asynchronous, written debate model - so write up your thoughts an

### Continuous Integration

Build and Test cycles are run on every commit to every branch using [GitHub Actions](https://github.com/TBD54566975/ssi-sdk/actions).
Build and Test cycles are run on every commit to every branch
using [GitHub Actions](https://github.com/TBD54566975/ssi-sdk/actions).

## Contribution

Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,11 @@ contributions for additional examples.
- [Decentralized Identifiers Example](example/did)
- [Verifiable Credentials Example](example/vc)
- Presentation Exchange Examples
- [Applying for an Apartment](example/usecase/apartment_application)
- [Employment Verification with a University Degree](example/usecase/employer_university_flow)
- [Applying for an Apartment](example/usecase/apartment_application)
- [Employment Verification with a University Degree](example/usecase/employer_university_flow)

To run the examples use the following command

```
go run example/did/did.go
go run example/usecase/apartment_application/apartment_application.go
Expand Down
2 changes: 1 addition & 1 deletion credential/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (vcb *VerifiableCredentialBuilder) Build() (*VerifiableCredential, error) {
}

if err := vcb.VerifiableCredential.IsValid(); err != nil {
return nil, util.LoggingErrorMsg(err, "credential not ready to be built")
return nil, errors.Wrap(err, "credential not ready to be built")
}

return vcb.VerifiableCredential, nil
Expand Down
6 changes: 3 additions & 3 deletions credential/exchange/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (pdb *PresentationDefinitionBuilder) Build() (*PresentationDefinition, erro
}

if err := pdb.PresentationDefinition.IsValid(); err != nil {
return nil, util.LoggingErrorMsg(err, "presentation definition not ready to be built")
return nil, errors.Wrap(err, "presentation definition not ready to be built")
}

return pdb.PresentationDefinition, nil
Expand Down Expand Up @@ -165,7 +165,7 @@ func (idb *InputDescriptorBuilder) Build() (*InputDescriptor, error) {
}

if err := idb.InputDescriptor.IsValid(); err != nil {
return nil, util.LoggingErrorMsg(err, "input descriptor not ready to be built")
return nil, errors.Wrap(err, "input descriptor not ready to be built")
}

return idb.InputDescriptor, nil
Expand Down Expand Up @@ -266,7 +266,7 @@ func (psb *PresentationSubmissionBuilder) Build() (*PresentationSubmission, erro
}

if err := psb.PresentationSubmission.IsValid(); err != nil {
return nil, util.LoggingErrorMsg(err, "presentation submission not ready to be built")
return nil, errors.Wrap(err, "presentation submission not ready to be built")
}

return psb.PresentationSubmission, nil
Expand Down
2 changes: 1 addition & 1 deletion credential/exchange/builder_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package exchange

import (
"encoding/json"
"testing"

"encoding/json"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"

Expand Down
22 changes: 5 additions & 17 deletions credential/exchange/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/google/uuid"
"github.com/lestrrat-go/jwx/jwt"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)

// PresentationRequestType represents wrappers for Presentation Definitions submitted as requests
Expand All @@ -35,9 +34,7 @@ func BuildPresentationRequest(signer crypto.JWTSigner, pt PresentationRequestTyp
case JWTRequest:
return BuildJWTPresentationRequest(signer, def, target)
default:
err := fmt.Errorf("presentation request type <%s> is not implemented", pt)
logrus.WithError(err).Error()
return nil, err
return nil, fmt.Errorf("presentation request type <%s> is not implemented", pt)
}
}

Expand All @@ -57,7 +54,6 @@ func BuildJWTPresentationRequest(signer crypto.JWTSigner, def PresentationDefini
func VerifyPresentationRequest(verifier crypto.JWTVerifier, pt PresentationRequestType, request []byte) (*PresentationDefinition, error) {
err := fmt.Errorf("cannot verify unsupported presentation request type: %s", pt)
if !IsSupportedPresentationRequestType(pt) {
logrus.WithError(err).Error()
return nil, err
}
switch pt {
Expand All @@ -73,27 +69,19 @@ func VerifyPresentationRequest(verifier crypto.JWTVerifier, pt PresentationReque
func VerifyJWTPresentationRequest(verifier crypto.JWTVerifier, request []byte) (*PresentationDefinition, error) {
parsed, err := verifier.VerifyAndParseJWT(string(request))
if err != nil {
err := errors.Wrap(err, "could not verify and parse jwt presentation request")
logrus.WithError(err).Error()
return nil, err
return nil, errors.Wrap(err, "could not verify and parse jwt presentation request")
}
presDefGeneric, ok := parsed.Get(PresentationDefinitionKey)
if !ok {
err := fmt.Errorf("presentation definition key<%s> not found in token", PresentationDefinitionKey)
logrus.WithError(err).Error()
return nil, err
return nil, fmt.Errorf("presentation definition key<%s> not found in token", PresentationDefinitionKey)
}
presDefBytes, err := json.Marshal(presDefGeneric)
if err != nil {
err := errors.Wrap(err, "could not marshal token into bytes for presentation definition")
logrus.WithError(err).Error()
return nil, err
return nil, errors.Wrap(err, "could not marshal token into bytes for presentation definition")
}
var def PresentationDefinition
if err := json.Unmarshal(presDefBytes, &def); err != nil {
err := errors.Wrap(err, "could not unmarshal token into presentation definition")
logrus.WithError(err).Error()
return nil, err
return nil, errors.Wrap(err, "could not unmarshal token into presentation definition")
}
return &def, nil
}
Expand Down
22 changes: 7 additions & 15 deletions credential/exchange/schema.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package exchange

import (
"github.com/TBD54566975/ssi-sdk/schema"
"github.com/goccy/go-json"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"

"github.com/TBD54566975/ssi-sdk/schema"
)

const (
Expand All @@ -29,8 +27,7 @@ func IsValidPresentationDefinition(definition PresentationDefinition) error {
return errors.Wrap(err, "could not get presentation definition schema")
}
if err = schema.IsJSONValidAgainstSchema(string(jsonBytes), s); err != nil {
logrus.WithError(err).Error("presentation definition not valid against schema")
return err
return errors.New("presentation definition not valid against schema")
}
return nil
}
Expand All @@ -46,8 +43,7 @@ func IsValidPresentationDefinitionEnvelope(definition PresentationDefinitionEnve
return errors.Wrap(err, "could not get presentation definition schema")
}
if err = schema.IsJSONValidAgainstSchema(string(jsonBytes), s); err != nil {
logrus.WithError(err).Error("presentation definition not valid against schema")
return err
return errors.Wrap(err, "presentation definition not valid against schema")
}
return nil
}
Expand All @@ -68,8 +64,7 @@ func IsValidPresentationSubmission(submission PresentationSubmission) error {
return errors.Wrap(err, "could not get presentation submission schema")
}
if err = schema.IsJSONValidAgainstSchema(string(jsonBytes), s); err != nil {
logrus.WithError(err).Error("submission declaration not valid against schema")
return err
return errors.Wrap(err, "submission declaration not valid against schema")
}
return nil
}
Expand All @@ -85,8 +80,7 @@ func IsValidDefinitionClaimFormatDesignation(format ClaimFormat) error {
return errors.Wrap(err, "could not get claim format schema")
}
if err = schema.IsJSONValidAgainstSchema(string(jsonBytes), s); err != nil {
logrus.WithError(err).Error("format declaration not valid against schema")
return err
return errors.Wrap(err, "format declaration not valid against schema")
}
return nil
}
Expand All @@ -102,8 +96,7 @@ func IsValidSubmissionRequirement(requirement SubmissionRequirement) error {
return errors.Wrap(err, "could not get submission requirement schema")
}
if err = schema.IsJSONValidAgainstSchema(string(jsonBytes), s); err != nil {
logrus.WithError(err).Error("submission requirement not valid against schema")
return err
return errors.Wrap(err, "submission requirement not valid against schema")
}
return nil
}
Expand All @@ -124,8 +117,7 @@ func AreValidSubmissionRequirements(requirements []SubmissionRequirement) error
return errors.Wrap(err, "could not get submission requirements schema")
}
if err = schema.IsJSONValidAgainstSchema(string(jsonBytes), s); err != nil {
logrus.WithError(err).Error("submission requirements not valid against schema")
return err
return errors.Wrap(err, "submission requirements not valid against schema")
}
return nil
}
Loading