Error package related codebase improvements
Remove/replace "github.com/pkg/errors" and "errors" with "fmt" or "corteza/server/pkg/errors" Closes #528
This commit is contained in:
Vendored
+10
-10
@@ -12,7 +12,6 @@ import (
|
||||
"github.com/cortezaproject/corteza/server/store"
|
||||
"github.com/cortezaproject/corteza/server/system/types"
|
||||
"github.com/crusttech/go-oidc"
|
||||
"github.com/pkg/errors"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -61,7 +60,8 @@ func AddProvider(ctx context.Context, log *zap.Logger, s store.SettingValues, ea
|
||||
}
|
||||
|
||||
// @todo remove dependency on github.com/crusttech/go-oidc (and github.com/coreos/go-oidc)
|
||||
// and move client registration to corteza codebase
|
||||
//
|
||||
// and move client registration to corteza codebase
|
||||
func DiscoverOidcProvider(ctx context.Context, log *zap.Logger, opt options.AuthOpt, name, url string) (eap *types.ExternalAuthProvider, err error) {
|
||||
var (
|
||||
provider *oidc.Provider
|
||||
@@ -129,7 +129,7 @@ func RegisterOidcProvider(ctx context.Context, log *zap.Logger, s store.SettingV
|
||||
}
|
||||
|
||||
if opt.ExternalRedirectURL == "" {
|
||||
return nil, errors.New("refusing to register OIDC provider without redirect url")
|
||||
return nil, fmt.Errorf("refusing to register OIDC provider without redirect url")
|
||||
}
|
||||
|
||||
p, err := parseExternalProviderUrl(providerUrl)
|
||||
@@ -198,7 +198,7 @@ func parseExternalProviderUrl(in string) (p *url.URL, err error) {
|
||||
// Simple checks of external auth settings
|
||||
func staticValidateExternal(opt options.AuthOpt) error {
|
||||
if opt.ExternalRedirectURL == "" {
|
||||
return errors.New("redirect URL is empty")
|
||||
return fmt.Errorf("redirect URL is empty")
|
||||
}
|
||||
|
||||
const (
|
||||
@@ -206,19 +206,19 @@ func staticValidateExternal(opt options.AuthOpt) error {
|
||||
)
|
||||
p, err := url.Parse(strings.Replace(opt.ExternalRedirectURL, "{provider}", tpt, 1))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "invalid redirect URL")
|
||||
return fmt.Errorf("invalid redirect URL", err)
|
||||
}
|
||||
|
||||
if !strings.Contains(p.Path, tpt+"/callback") {
|
||||
return errors.Wrap(err, "could find injected provider in the URL, make sure you use '%s' as a placeholder")
|
||||
return fmt.Errorf("could find injected provider in the URL, make sure you use '%%s' as a placeholder", err)
|
||||
}
|
||||
|
||||
if opt.ExternalCookieSecret == "" {
|
||||
return errors.New("AUTH_EXTERNAL_COOKIE_SECRET is empty")
|
||||
return fmt.Errorf("AUTH_EXTERNAL_COOKIE_SECRET is empty")
|
||||
}
|
||||
|
||||
if opt.SessionCookieSecure && p.Scheme != "https" {
|
||||
return errors.New("session store is secure, redirect URL should have HTTPS")
|
||||
return fmt.Errorf("session store is secure, redirect URL should have HTTPS")
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -237,7 +237,7 @@ func validateExternalRedirectURL(opt options.AuthOpt) error {
|
||||
|
||||
rsp, err := http.DefaultClient.Get(url)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not get response from redirect URL")
|
||||
return fmt.Errorf("could not get response from redirect URL", err)
|
||||
}
|
||||
|
||||
defer rsp.Body.Close()
|
||||
@@ -247,5 +247,5 @@ func validateExternalRedirectURL(opt options.AuthOpt) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
return errors.New("could not validate external auth redirection URL")
|
||||
return fmt.Errorf("could not validate external auth redirection URL")
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ func Test_createPasswordForm(t *testing.T) {
|
||||
return false
|
||||
},
|
||||
validatePasswordCreateToken: func(ctx context.Context, token string) (user *types.User, err error) {
|
||||
return nil, errors.New("invalid token")
|
||||
return nil, fmt.Errorf("invalid token")
|
||||
},
|
||||
}
|
||||
},
|
||||
@@ -83,7 +83,7 @@ func Test_createPasswordForm(t *testing.T) {
|
||||
return false
|
||||
},
|
||||
validatePasswordCreateToken: func(ctx context.Context, token string) (user *types.User, err error) {
|
||||
return nil, errors.New("invalid token")
|
||||
return nil, fmt.Errorf("invalid token")
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
@@ -51,7 +51,7 @@ func Test_oauth2AuthorizeSuccess(t *testing.T) {
|
||||
fn: func(_ *settings.Settings) {
|
||||
oauthService = &oauth2ServiceMocked{
|
||||
handleAuthorizeRequest: func(w http.ResponseWriter, r *http.Request) error {
|
||||
return errors.New("not authorized")
|
||||
return fmt.Errorf("not authorized")
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
@@ -86,7 +86,7 @@ func Test_resetPasswordForm(t *testing.T) {
|
||||
|
||||
authService = &authServiceMocked{
|
||||
validatePasswordResetToken: func(ctx context.Context, token string) (user *types.User, err error) {
|
||||
return nil, errors.New("invalid token")
|
||||
return nil, fmt.Errorf("invalid token")
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
@@ -81,7 +81,7 @@ func Test_securityProc(t *testing.T) {
|
||||
|
||||
authService = &authServiceMocked{
|
||||
configureEmailOTP: func(c context.Context, u uint64, b bool) (user *types.User, err error) {
|
||||
return nil, errors.New("custom error")
|
||||
return nil, fmt.Errorf("custom error")
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
@@ -3,13 +3,13 @@ package saml
|
||||
import (
|
||||
"crypto/rsa"
|
||||
"crypto/x509"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/crewjam/saml"
|
||||
"github.com/crewjam/saml/samlsp"
|
||||
"github.com/pkg/errors"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -89,7 +89,7 @@ func NewSamlSPService(log *zap.Logger, args SamlSPArgs) (s *SamlSPService, err e
|
||||
// internal samlsp service
|
||||
handler, err := samlsp.New(opts)
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "could not init SAML SP handler")
|
||||
err = fmt.Errorf("could not init SAML SP handler", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ func TestJwtHandler(t *testing.T) {
|
||||
{
|
||||
name: "proxy processer with auth headers",
|
||||
exp: "",
|
||||
err: errors.New("could not generate JWT, payload missing"),
|
||||
err: fmt.Errorf("could not generate JWT, payload missing"),
|
||||
params: &jwtGenerateArgs{
|
||||
hasHeader: true,
|
||||
hasPayload: false,
|
||||
@@ -90,7 +90,7 @@ func TestJwtHandler(t *testing.T) {
|
||||
{
|
||||
name: "proxy processer with auth headers",
|
||||
exp: "",
|
||||
err: errors.New("could not generate JWT, secret or cert missing"),
|
||||
err: fmt.Errorf("could not generate JWT, secret or cert missing"),
|
||||
params: &jwtGenerateArgs{
|
||||
hasHeader: true,
|
||||
hasPayload: true,
|
||||
|
||||
@@ -2,7 +2,6 @@ package automation
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/cortezaproject/corteza/server/compose/types"
|
||||
@@ -373,7 +372,7 @@ func (h recordsHandler) fetchEdge(ctx context.Context, args interface{}, first b
|
||||
return nil, err
|
||||
}
|
||||
if len(rr) == 0 {
|
||||
return nil, errors.New("could not fetch records: no records found")
|
||||
return nil, fmt.Errorf("could not fetch records: no records found")
|
||||
}
|
||||
return rr[0], nil
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package rest
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/cortezaproject/corteza/server/pkg/errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -12,11 +13,8 @@ import (
|
||||
"github.com/cortezaproject/corteza/server/compose/types"
|
||||
"github.com/cortezaproject/corteza/server/pkg/api"
|
||||
"github.com/cortezaproject/corteza/server/pkg/auth"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var _ = errors.Wrap
|
||||
|
||||
type (
|
||||
attachmentPayload struct {
|
||||
*types.Attachment
|
||||
@@ -41,7 +39,7 @@ func (Attachment) New() *Attachment {
|
||||
// Attachments returns list of all files attached to records
|
||||
func (ctrl Attachment) List(ctx context.Context, r *request.AttachmentList) (interface{}, error) {
|
||||
if !auth.GetIdentityFromContext(ctx).Valid() {
|
||||
return nil, errors.New("Unauthorized")
|
||||
return nil, errors.Unauthorized("cannot list attachments")
|
||||
}
|
||||
|
||||
f := types.AttachmentFilter{
|
||||
@@ -58,7 +56,7 @@ func (ctrl Attachment) List(ctx context.Context, r *request.AttachmentList) (int
|
||||
|
||||
func (ctrl Attachment) Read(ctx context.Context, r *request.AttachmentRead) (interface{}, error) {
|
||||
if !auth.GetIdentityFromContext(ctx).Valid() {
|
||||
return nil, errors.New("Unauthorized")
|
||||
return nil, errors.Unauthorized("cannot read attachment")
|
||||
}
|
||||
|
||||
a, err := ctrl.attachment.FindByID(ctx, r.NamespaceID, r.AttachmentID)
|
||||
@@ -67,7 +65,7 @@ func (ctrl Attachment) Read(ctx context.Context, r *request.AttachmentRead) (int
|
||||
|
||||
func (ctrl Attachment) Delete(ctx context.Context, r *request.AttachmentDelete) (interface{}, error) {
|
||||
if !auth.GetIdentityFromContext(ctx).Valid() {
|
||||
return nil, errors.New("Unauthorized")
|
||||
return nil, errors.Unauthorized("cannot delete attachment")
|
||||
}
|
||||
|
||||
_, err := ctrl.attachment.FindByID(ctx, r.NamespaceID, r.AttachmentID)
|
||||
@@ -96,19 +94,19 @@ func (ctrl Attachment) Preview(ctx context.Context, r *request.AttachmentPreview
|
||||
|
||||
func (ctrl Attachment) isAccessible(namespaceID, attachmentID, userID uint64, signature string) error {
|
||||
if signature == "" {
|
||||
return errors.New("Unauthorized")
|
||||
return errors.Unauthorized("missing signature")
|
||||
}
|
||||
|
||||
if userID == 0 {
|
||||
return errors.New("missing or invalid user ID")
|
||||
return errors.InvalidData("missing or invalid user ID")
|
||||
}
|
||||
|
||||
if attachmentID == 0 {
|
||||
return errors.New("missing or invalid attachment ID")
|
||||
return errors.InvalidData("missing or invalid attachment ID")
|
||||
}
|
||||
|
||||
if !auth.DefaultSigner.Verify(signature, userID, namespaceID, attachmentID) {
|
||||
return errors.New("missing or invalid signature")
|
||||
return errors.InvalidData("missing or invalid signature")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -8,11 +8,8 @@ import (
|
||||
"github.com/cortezaproject/corteza/server/compose/rest/request"
|
||||
"github.com/cortezaproject/corteza/server/compose/service/event"
|
||||
"github.com/cortezaproject/corteza/server/pkg/corredor"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var _ = errors.Wrap
|
||||
|
||||
type (
|
||||
Automation struct{}
|
||||
)
|
||||
|
||||
@@ -8,11 +8,8 @@ import (
|
||||
"github.com/cortezaproject/corteza/server/compose/types"
|
||||
"github.com/cortezaproject/corteza/server/pkg/api"
|
||||
"github.com/cortezaproject/corteza/server/pkg/filter"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var _ = errors.Wrap
|
||||
|
||||
type (
|
||||
chartPayload struct {
|
||||
*types.Chart
|
||||
|
||||
@@ -575,7 +575,7 @@ func (svc attachment) processImage(original io.ReadSeeker, att *types.Attachment
|
||||
if imaging.JPEG == format {
|
||||
// Rotate image if needed
|
||||
// if preview, _, err = exiffix.Decode(original); err != nil {
|
||||
// return errors.Wrapf(err, "Could not decode EXIF from JPEG")
|
||||
// return fmt.Errorf("Could not decode EXIF from JPEG", err)
|
||||
// }
|
||||
preview, _, _ = exiffix.Decode(original)
|
||||
}
|
||||
|
||||
@@ -226,5 +226,5 @@ func (s testRecordServiceDeleteSuccess) Find(_ context.Context, filter ct.Record
|
||||
|
||||
// create error
|
||||
func (s testRecordServicePersistError) Create(_ context.Context, record *ct.Record) (*ct.Record, *ct.RecordValueErrorSet, error) {
|
||||
return nil, nil, errors.New("mocked error")
|
||||
return nil, nil, fmt.Errorf("mocked error")
|
||||
}
|
||||
|
||||
@@ -176,7 +176,7 @@ func TestProcesserStructure_persist(t *testing.T) {
|
||||
}
|
||||
|
||||
func (s testStructureSharedModuleServiceError) Find(ctx context.Context, filter types.SharedModuleFilter) (types.SharedModuleSet, types.SharedModuleFilter, error) {
|
||||
return types.SharedModuleSet{}, types.SharedModuleFilter{}, errors.New("db error")
|
||||
return types.SharedModuleSet{}, types.SharedModuleFilter{}, fmt.Errorf("db error")
|
||||
}
|
||||
|
||||
func (s testStructureSharedModuleServiceCreateNewModule) Find(ctx context.Context, filter types.SharedModuleFilter) (types.SharedModuleSet, types.SharedModuleFilter, error) {
|
||||
@@ -192,7 +192,7 @@ func (s testStructureSharedModuleServiceCreateNewModuleErr) Find(ctx context.Con
|
||||
}
|
||||
|
||||
func (s testStructureSharedModuleServiceCreateNewModuleErr) Create(ctx context.Context, new *types.SharedModule) (*types.SharedModule, error) {
|
||||
return nil, errors.New("could not create new module")
|
||||
return nil, fmt.Errorf("could not create new module")
|
||||
}
|
||||
|
||||
func (s testStructureSharedModuleServiceUpdateModule) Find(ctx context.Context, filter types.SharedModuleFilter) (types.SharedModuleSet, types.SharedModuleFilter, error) {
|
||||
@@ -228,5 +228,5 @@ func (s testStructureSharedModuleServiceUpdateModuleErr) Find(ctx context.Contex
|
||||
}
|
||||
|
||||
func (s testStructureSharedModuleServiceUpdateModuleErr) Update(ctx context.Context, updated *types.SharedModule) (*types.SharedModule, error) {
|
||||
return nil, errors.New("could not update module")
|
||||
return nil, fmt.Errorf("could not update module")
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
ErrorURIMissingToken = errors.New("uri: token missing")
|
||||
ErrorURIMissingToken = fmt.Errorf("uri: token missing")
|
||||
)
|
||||
|
||||
const ()
|
||||
|
||||
@@ -2,6 +2,7 @@ package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -11,7 +12,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/pkg/errors"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -164,12 +164,12 @@ func (s server) probeService(ctx context.Context, addr string) (err error) {
|
||||
func (s server) probeServiceURL(ctx context.Context, u *url.URL) error {
|
||||
req, err := http.NewRequest("GET", u.String(), nil)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to assemble service request")
|
||||
return fmt.Errorf("failed to assemble service request", err)
|
||||
}
|
||||
|
||||
rsp, err := http.DefaultClient.Do(req.WithContext(ctx))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "service URL request failed")
|
||||
return fmt.Errorf("service URL request failed", err)
|
||||
}
|
||||
|
||||
defer rsp.Body.Close()
|
||||
@@ -177,5 +177,5 @@ func (s server) probeServiceURL(ctx context.Context, u *url.URL) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
return errors.Errorf("service responded with unexpected status '%s'", rsp.Status)
|
||||
return fmt.Errorf("service responded with unexpected status '%s'", rsp.Status)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package filter
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
@@ -127,7 +126,7 @@ func (h header) Handler() types.HandlerFunc {
|
||||
}
|
||||
|
||||
if !b {
|
||||
return pe.InvalidData("could not validate headers: %v", errors.New("validation failed"))
|
||||
return pe.InvalidData("could not validate headers: %v", fmt.Errorf("validation failed"))
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -215,7 +214,7 @@ func (qp *queryParam) Handler() types.HandlerFunc {
|
||||
}
|
||||
|
||||
if !b {
|
||||
return pe.InvalidData("could not validate query parameters: %v", errors.New("validation failed"))
|
||||
return pe.InvalidData("could not validate query parameters: %v", fmt.Errorf("validation failed"))
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
@@ -200,7 +199,7 @@ func (h *processerPayload) Merge(params []byte) (types.Handler, error) {
|
||||
}
|
||||
|
||||
if h.params.Func == "" {
|
||||
return nil, errors.New("could not register function, body empty")
|
||||
return nil, fmt.Errorf("could not register function, body empty")
|
||||
}
|
||||
|
||||
if h.fn, err = h.vm.RegisterFunction(h.params.Func); err != nil {
|
||||
|
||||
@@ -51,7 +51,7 @@ func Test_processerWorkflow(t *testing.T) {
|
||||
return nil
|
||||
},
|
||||
exec: func(ctx context.Context, workflowID uint64, p atypes.WorkflowExecParams) (*expr.Vars, uint64, atypes.Stacktrace, error) {
|
||||
return must(expr.NewVars(map[string]interface{}{"foo": "bar"})), 0, make([]*wfexec.Frame, 0), errors.New("mocked error")
|
||||
return must(expr.NewVars(map[string]interface{}{"foo": "bar"})), 0, make([]*wfexec.Frame, 0), fmt.Errorf("mocked error")
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -90,7 +90,7 @@ func Test_pipelineExecErr(t *testing.T) {
|
||||
name: "matching simple",
|
||||
mh: types.MockHandler{
|
||||
Handler_: func(rw http.ResponseWriter, r *http.Request) error {
|
||||
return errors.New("triggered")
|
||||
return fmt.Errorf("triggered")
|
||||
}},
|
||||
w: &Worker{},
|
||||
exp: `{"error":{"message":"triggered"}}` + "\n",
|
||||
|
||||
@@ -46,7 +46,7 @@ func Test_pl(t *testing.T) {
|
||||
handler: &types.MockHandler{
|
||||
Handler_: func(rw http.ResponseWriter, r *http.Request) error {
|
||||
rw.WriteHeader(http.StatusTemporaryRedirect)
|
||||
return errors.New("test error")
|
||||
return fmt.Errorf("test error")
|
||||
},
|
||||
},
|
||||
errHandler: &types.MockErrorHandler{
|
||||
@@ -63,7 +63,7 @@ func Test_pl(t *testing.T) {
|
||||
handler: &types.MockHandler{
|
||||
Handler_: func(rw http.ResponseWriter, r *http.Request) error {
|
||||
rw.WriteHeader(http.StatusTemporaryRedirect)
|
||||
return errors.New("test error")
|
||||
return fmt.Errorf("test error")
|
||||
},
|
||||
},
|
||||
method: "POST",
|
||||
|
||||
@@ -145,7 +145,7 @@ func Test_serviceInit(t *testing.T) {
|
||||
reg: map[string]types.Handler{"testExistingFilter": &mockExistingHandler{
|
||||
MockHandler: &types.MockHandler{},
|
||||
merge: func(params []byte) (types.Handler, error) {
|
||||
return nil, errors.New("testttt")
|
||||
return nil, fmt.Errorf("testttt")
|
||||
},
|
||||
}},
|
||||
expLen: 0,
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/cortezaproject/corteza/server/pkg/options"
|
||||
"github.com/pkg/errors"
|
||||
"go.uber.org/zap"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials"
|
||||
@@ -69,7 +68,7 @@ func NewConnection(ctx context.Context, opt options.CorredorOpt, logger *zap.Log
|
||||
|
||||
// Append the client certificates from the CA
|
||||
if ok := certPool.AppendCertsFromPEM(ca); !ok {
|
||||
return nil, errors.New("failed to append ca certs" + expl)
|
||||
return nil, fmt.Errorf("failed to append ca certs" + expl)
|
||||
}
|
||||
|
||||
crds := credentials.NewTLS(&tls.Config{
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"fmt"
|
||||
"github.com/cortezaproject/corteza/server/pkg/eventbus"
|
||||
"github.com/cortezaproject/corteza/server/pkg/slice"
|
||||
"github.com/pkg/errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
@@ -73,7 +72,7 @@ func triggerToHandlerOps(t *Trigger) (oo []eventbus.HandlerRegOp, err error) {
|
||||
func constraintsToHandlerOps(cc []*TConstraint) (oo []eventbus.HandlerRegOp, err error) {
|
||||
for _, raw := range cc {
|
||||
if c, err := eventbus.ConstraintMaker(raw.Name, raw.Op, raw.Value...); err != nil {
|
||||
return nil, errors.Wrap(err, "cannot generate constraints")
|
||||
return nil, fmt.Errorf("cannot generate constraints", err)
|
||||
} else {
|
||||
oo = append(oo, eventbus.Constraint(c))
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package envoy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/cortezaproject/corteza/server/pkg/envoy/resource"
|
||||
@@ -49,7 +49,7 @@ type (
|
||||
)
|
||||
|
||||
var (
|
||||
BuilderErrUnresolvedReferences = errors.New("builder error: unresolved references")
|
||||
BuilderErrUnresolvedReferences = fmt.Errorf("builder error: unresolved references")
|
||||
)
|
||||
|
||||
func NewBuilder(pp ...Preparer) *builder {
|
||||
@@ -68,11 +68,11 @@ func NewSafeBuilder(pp ...Preparer) *builder {
|
||||
// Build builds the graph that is used for structured data processing
|
||||
//
|
||||
// Outline:
|
||||
// 1. Build an initial graph so that we can do some structured preprocessing.
|
||||
// 2. Preprocess the resources based on the initial graph. The initial graph
|
||||
// should remain unchanged. Preprocessing can request additional references and
|
||||
// constraints.
|
||||
// 3. Build a final graph based on the preprocessing modifications.
|
||||
// 1. Build an initial graph so that we can do some structured preprocessing.
|
||||
// 2. Preprocess the resources based on the initial graph. The initial graph
|
||||
// should remain unchanged. Preprocessing can request additional references and
|
||||
// constraints.
|
||||
// 3. Build a final graph based on the preprocessing modifications.
|
||||
func (b *builder) Build(ctx context.Context, rr ...resource.Interface) (*graph, error) {
|
||||
var err error
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package csv
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
@@ -49,8 +48,8 @@ type (
|
||||
)
|
||||
|
||||
var (
|
||||
ErrUnknownResource = errors.New("unknown resource")
|
||||
ErrResourceStateUndefined = errors.New("undefined resource state")
|
||||
ErrUnknownResource = fmt.Errorf("unknown resource")
|
||||
ErrResourceStateUndefined = fmt.Errorf("undefined resource state")
|
||||
)
|
||||
|
||||
func NewBulkRecordEncoder(cfg *EncoderConfig) envoy.PrepareEncodeStreamer {
|
||||
|
||||
@@ -2,7 +2,7 @@ package envoy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/cortezaproject/corteza/server/pkg/envoy/resource"
|
||||
)
|
||||
@@ -134,7 +134,7 @@ func (g *graph) Next(ctx context.Context) (s *ResourceState, err error) {
|
||||
|
||||
if nx == nil {
|
||||
// This is basically impossible, unless I've messed up the algorithm
|
||||
return nil, errors.New("could not determine non-conflicting node")
|
||||
return nil, fmt.Errorf("could not determine non-conflicting node")
|
||||
}
|
||||
|
||||
// Prepare the required context for the processing.
|
||||
@@ -147,13 +147,14 @@ func (g *graph) Next(ctx context.Context) (s *ResourceState, err error) {
|
||||
// findCycleNode returns the first graph node that caused a cycle
|
||||
//
|
||||
// General outline:
|
||||
// * DFS from a start node(s)
|
||||
// * if a child node is already in path, return that node
|
||||
// * else return nil and cleanup the path until the first node with
|
||||
// unprocessed child nodes
|
||||
// - DFS from a start node(s)
|
||||
// - if a child node is already in path, return that node
|
||||
// - else return nil and cleanup the path until the first node with
|
||||
// unprocessed child nodes
|
||||
//
|
||||
// @note we could complicate this further by doing cycle enumeration algorithms.
|
||||
// I might do it when no one is watching :)
|
||||
//
|
||||
// I might do it when no one is watching :)
|
||||
func (g *graph) findCycleNode(nn nodeSet) *node {
|
||||
path := make(nodeMap)
|
||||
processed := make(nodeMap)
|
||||
|
||||
@@ -3,7 +3,6 @@ package json
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
@@ -49,8 +48,8 @@ type (
|
||||
)
|
||||
|
||||
var (
|
||||
ErrUnknownResource = errors.New("unknown resource")
|
||||
ErrResourceStateUndefined = errors.New("undefined resource state")
|
||||
ErrUnknownResource = fmt.Errorf("unknown resource")
|
||||
ErrResourceStateUndefined = fmt.Errorf("undefined resource state")
|
||||
)
|
||||
|
||||
func NewBulkRecordEncoder(cfg *EncoderConfig) envoy.PrepareEncodeStreamer {
|
||||
|
||||
@@ -2,7 +2,7 @@ package resource
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/cortezaproject/corteza/server/system/types"
|
||||
@@ -55,7 +55,7 @@ func (us *Userstamp) MarshalYAML() (interface{}, error) {
|
||||
return us.UserID, nil
|
||||
}
|
||||
|
||||
return nil, errors.New("invalid userstamp")
|
||||
return nil, fmt.Errorf("invalid userstamp")
|
||||
}
|
||||
|
||||
func (us *Userstamp) MarshalJSON() ([]byte, error) {
|
||||
@@ -89,7 +89,7 @@ func (us *Userstamp) MarshalJSON() ([]byte, error) {
|
||||
}
|
||||
|
||||
if l == "" {
|
||||
return nil, errors.New("invalid userstamp")
|
||||
return nil, fmt.Errorf("invalid userstamp")
|
||||
}
|
||||
|
||||
return json.Marshal(l)
|
||||
@@ -193,7 +193,7 @@ func (us *Userstamp) Model() (string, error) {
|
||||
return strconv.FormatUint(us.UserID, 10), nil
|
||||
}
|
||||
|
||||
return "", errors.New("invalid userstamp")
|
||||
return "", fmt.Errorf("invalid userstamp")
|
||||
}
|
||||
|
||||
func (ux UserstampIndex) Add(uu ...*types.User) {
|
||||
|
||||
@@ -2,7 +2,6 @@ package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/cortezaproject/corteza/server/compose/types"
|
||||
@@ -77,8 +76,8 @@ type (
|
||||
)
|
||||
|
||||
var (
|
||||
ErrUnknownResource = errors.New("unknown resource")
|
||||
ErrResourceStateUndefined = errors.New("undefined resource state")
|
||||
ErrUnknownResource = fmt.Errorf("unknown resource")
|
||||
ErrResourceStateUndefined = fmt.Errorf("undefined resource state")
|
||||
)
|
||||
|
||||
// NewStoreEncoder initializes a fresh store encoder
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package yaml
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
@@ -80,7 +79,7 @@ func (wrap *composeRecord) UnmarshalYAML(n *yaml.Node) (err error) {
|
||||
return y7s.DecodeScalar(v, "module", &wrap.refModule)
|
||||
|
||||
case "allow", "deny":
|
||||
return errors.New("compose record RBAC rules not supported on resource level")
|
||||
return fmt.Errorf("compose record RBAC rules not supported on resource level")
|
||||
|
||||
case "values":
|
||||
// Use aux structure to decode record values into RVS
|
||||
|
||||
@@ -3,7 +3,6 @@ package yaml
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
@@ -74,9 +73,9 @@ type (
|
||||
)
|
||||
|
||||
var (
|
||||
ErrUnknownResource = errors.New("unknown resource")
|
||||
ErrResourceStateUndefined = errors.New("undefined resource state")
|
||||
ErrInvalidResourceType = errors.New("invalid resource state")
|
||||
ErrUnknownResource = fmt.Errorf("unknown resource")
|
||||
ErrResourceStateUndefined = fmt.Errorf("undefined resource state")
|
||||
ErrInvalidResourceType = fmt.Errorf("invalid resource state")
|
||||
)
|
||||
|
||||
// NewYamlEncoder initializes a fresh yaml encoder
|
||||
@@ -173,7 +172,8 @@ func (ye *yamlEncoder) Prepare(ctx context.Context, ee ...*envoy.ResourceState)
|
||||
// to different namespaces).
|
||||
//
|
||||
// @todo improve document structuring; the base encodes each resource type into it's own document.
|
||||
// This is good enough for now but should be expanded in the near future.
|
||||
//
|
||||
// This is good enough for now but should be expanded in the near future.
|
||||
func (ye *yamlEncoder) Encode(ctx context.Context, p envoy.Provider) error {
|
||||
var e *envoy.ResourceState
|
||||
var err error
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package yaml
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
@@ -126,7 +125,7 @@ func seqToMap(ss *yaml.Node, k string) (*yaml.Node, error) {
|
||||
}
|
||||
|
||||
if kn == nil {
|
||||
return nil, errors.New("key field not defined")
|
||||
return nil, fmt.Errorf("key field not defined")
|
||||
}
|
||||
|
||||
mm, err = addMap(mm, kn.Value, s)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package eventbus
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"path"
|
||||
"regexp"
|
||||
"strings"
|
||||
@@ -35,8 +35,8 @@ type (
|
||||
constraintSet []ConstraintMatcher
|
||||
)
|
||||
|
||||
var ErrUnsupportedOp = errors.New("operator not supported")
|
||||
var ErrUnsupportedName = errors.New("constraint name not supported")
|
||||
var ErrUnsupportedOp = fmt.Errorf("operator not supported")
|
||||
var ErrUnsupportedName = fmt.Errorf("constraint name not supported")
|
||||
|
||||
func (c mustBeEqual) Name() string { return c.name }
|
||||
func (c mustBeLike) Name() string { return c.name }
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package expr
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"math/rand"
|
||||
|
||||
"github.com/PaesslerAG/gval"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
@@ -125,18 +125,18 @@ func random(v ...float64) (out float64, err error) {
|
||||
)
|
||||
|
||||
if totalArgs == 0 || totalArgs > 2 {
|
||||
return 0, errors.Errorf("expecting 1 or 2 parameter, got %d", totalArgs)
|
||||
return 0, fmt.Errorf("expecting 1 or 2 parameter, got %d", totalArgs)
|
||||
}
|
||||
|
||||
if totalArgs > 0 {
|
||||
if to = v[0]; to < 0 {
|
||||
return 0, errors.New("unexpected input type of 1st parameter")
|
||||
return 0, fmt.Errorf("unexpected input type of 1st parameter")
|
||||
}
|
||||
}
|
||||
|
||||
if totalArgs > 1 {
|
||||
if to = v[1]; to < 0 {
|
||||
return 0, errors.New("unexpected input type of 2nd parameter")
|
||||
return 0, fmt.Errorf("unexpected input type of 2nd parameter")
|
||||
}
|
||||
from = v[0]
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package expr
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"reflect"
|
||||
@@ -122,7 +121,7 @@ func join(arr interface{}, sep string) (out string, err error) {
|
||||
// Make an aux string slice so the join operation can use it
|
||||
stv, is := arr.([]TypedValue)
|
||||
if !is {
|
||||
return "", errors.New("could not cast array to string array")
|
||||
return "", fmt.Errorf("could not cast array to string array")
|
||||
}
|
||||
|
||||
aux := make([]string, len(stv))
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package expr
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/PaesslerAG/gval"
|
||||
@@ -179,7 +179,7 @@ func sub(from interface{}, to interface{}) (out int64, err error) {
|
||||
if t1.After(*t2) {
|
||||
duration = t1.Sub(*t2)
|
||||
} else {
|
||||
return -1, errors.New("expecting 2nd input to be less than 1st input")
|
||||
return -1, fmt.Errorf("expecting 2nd input to be less than 1st input")
|
||||
}
|
||||
|
||||
return duration.Milliseconds(), nil
|
||||
|
||||
@@ -10,8 +10,6 @@ import (
|
||||
"net/http/httputil"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -105,7 +103,7 @@ func (c *Client) Request(method, url string, body interface{}) (*http.Request, e
|
||||
|
||||
req, err := request()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "creating request failed")
|
||||
return nil, fmt.Errorf("creating request failed", err)
|
||||
}
|
||||
req.Header.Add("Content-Type", "application/json")
|
||||
return req, nil
|
||||
@@ -147,7 +145,7 @@ func (c *Client) Do(req *http.Request) (*http.Response, error) {
|
||||
if c.debugLevel == INFO {
|
||||
fmt.Println("HTTP <<< Response error", err)
|
||||
}
|
||||
return nil, errors.Wrap(err, "request failed")
|
||||
return nil, fmt.Errorf("request failed", err)
|
||||
}
|
||||
if c.debugLevel == INFO {
|
||||
fmt.Println("HTTP <<< Response", resp.StatusCode)
|
||||
@@ -158,7 +156,7 @@ func (c *Client) Do(req *http.Request) (*http.Response, error) {
|
||||
func ToError(resp *http.Response) error {
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if body == nil || err != nil {
|
||||
return errors.Errorf("unexpected response (%d, %s)", resp.StatusCode, err)
|
||||
return fmt.Errorf("unexpected response (%d, %s)", resp.StatusCode, err)
|
||||
}
|
||||
return errors.New(string(body))
|
||||
return fmt.Errorf(string(body))
|
||||
}
|
||||
|
||||
@@ -3,12 +3,11 @@ package http
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -84,10 +83,10 @@ func (r *BufferedReader) Seek(offset int64, whence int) (int64, error) {
|
||||
case io.SeekEnd:
|
||||
abs = int64(len(r.s)) + offset
|
||||
default:
|
||||
return 0, errors.New("bytes.Reader.Seek: invalid whence")
|
||||
return 0, fmt.Errorf("bytes.Reader.Seek: invalid whence")
|
||||
}
|
||||
if abs < 0 {
|
||||
return 0, errors.New("bytes.Reader.Seek: negative position")
|
||||
return 0, fmt.Errorf("bytes.Reader.Seek: negative position")
|
||||
}
|
||||
r.i = abs
|
||||
return abs, nil
|
||||
|
||||
@@ -3,7 +3,6 @@ package jsenv
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/dop251/goja"
|
||||
@@ -66,14 +65,14 @@ func (ss Vm) RegisterFunction(s string, wrapperFn ...func() string) (f *Fn, err
|
||||
internalF := ss.Fetch(desc)
|
||||
|
||||
if internalF == nil {
|
||||
err = errors.New("could not fetch registered value")
|
||||
err = fmt.Errorf("could not fetch registered value")
|
||||
return
|
||||
}
|
||||
|
||||
fnn, ok := goja.AssertFunction(internalF)
|
||||
|
||||
if !ok {
|
||||
err = errors.New("could not assert function")
|
||||
err = fmt.Errorf("could not assert function")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ func TestMailSendWithoutDialer(t *testing.T) {
|
||||
}
|
||||
|
||||
defaultDialer = nil
|
||||
defaultDialerError = errors.New("Default dialer init error")
|
||||
defaultDialerError = fmt.Errorf("Default dialer init error")
|
||||
{
|
||||
err := Send(msg)
|
||||
require.True(t, err != nil, "Send() should return an error, got %v", err)
|
||||
@@ -86,7 +86,7 @@ func TestMailSendErrors(t *testing.T) {
|
||||
msg := New()
|
||||
|
||||
sDailer := NewMockDialer(mockCtrl)
|
||||
sDailer.EXPECT().DialAndSend(msg).Times(1).Return(errors.New("some-error"))
|
||||
sDailer.EXPECT().DialAndSend(msg).Times(1).Return(fmt.Errorf("some-error"))
|
||||
|
||||
err := Send(msg, sDailer)
|
||||
require.True(t, err != nil, "Send() should return an error, got: %v", err)
|
||||
|
||||
@@ -31,10 +31,10 @@ var (
|
||||
|
||||
unsuccessfulClient = mockClient{
|
||||
add: func(c context.Context, q string, p []byte) error {
|
||||
return errors.New("could not write messages")
|
||||
return fmt.Errorf("could not write messages")
|
||||
},
|
||||
process: func(c context.Context, u uint64, qm types.QueueMessage) (err error) {
|
||||
return errors.New("could not process messages")
|
||||
return fmt.Errorf("could not process messages")
|
||||
},
|
||||
}
|
||||
)
|
||||
@@ -55,7 +55,7 @@ func Test_handlerSqlWrite(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "write error",
|
||||
err: errors.New("could not write messages"),
|
||||
err: fmt.Errorf("could not write messages"),
|
||||
client: &unsuccessfulClient,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
minio "github.com/minio/minio-go/v6"
|
||||
"github.com/minio/minio-go/v6/pkg/encrypt"
|
||||
"github.com/minio/minio-go/v6/pkg/s3utils"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -82,7 +81,7 @@ func newWithClient(mc minioClient, bucket, pathPrefix, component string, opt Opt
|
||||
return nil, err
|
||||
} else if !e {
|
||||
if opt.Strict {
|
||||
return nil, errors.Errorf("bucket %q does not exist", s.bucket)
|
||||
return nil, fmt.Errorf("bucket %q does not exist", s.bucket)
|
||||
}
|
||||
|
||||
err = s.mc.MakeBucket(s.bucket, "us-east-1")
|
||||
@@ -103,7 +102,7 @@ func newWithClient(mc minioClient, bucket, pathPrefix, component string, opt Opt
|
||||
|
||||
func (s *store) check(name string) error {
|
||||
if len(name) == 0 {
|
||||
return errors.Errorf("Invalid name when trying to store object: '%s' (for %s)", name, s.bucket)
|
||||
return fmt.Errorf("Invalid name when trying to store object: '%s' (for %s)", name, s.bucket)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"io"
|
||||
"path"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/afero"
|
||||
)
|
||||
|
||||
@@ -48,11 +47,11 @@ func NewWithAfero(fs afero.Fs, namespace string) (*store, error) {
|
||||
|
||||
func (s *store) check(filename string) error {
|
||||
if len(filename) == 0 {
|
||||
return errors.Errorf("Invalid filename when trying to store file: '%s' (for %s)", filename, s.namespace)
|
||||
return fmt.Errorf("Invalid filename when trying to store file: '%s' (for %s)", filename, s.namespace)
|
||||
}
|
||||
|
||||
if filename[:len(s.namespace)+1] != s.namespace+"/" {
|
||||
return errors.Errorf("Invalid namespace when trying to store file: '%s' (for %s)", filename, s.namespace)
|
||||
return fmt.Errorf("Invalid namespace when trying to store file: '%s' (for %s)", filename, s.namespace)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package objstore
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/pkg/errors"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"net/url"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/cortezaproject/corteza/server/pkg/http"
|
||||
)
|
||||
|
||||
@@ -14,7 +14,7 @@ func FromURL(fileURL string) (io.ReadCloser, error) {
|
||||
if u, err := url.ParseRequestURI(fileURL); err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
} else if u.Scheme != "https" {
|
||||
return nil, errors.New("Only HTTPS is supported for file uploads")
|
||||
return nil, fmt.Errorf("Only HTTPS is supported for file uploads")
|
||||
}
|
||||
|
||||
client, err := http.New(&http.Config{
|
||||
|
||||
@@ -2,7 +2,6 @@ package ql
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -91,7 +90,7 @@ func (t *typedValue) UnmarshalJSON(in []byte) (err error) {
|
||||
}
|
||||
|
||||
if aux.Type == "" {
|
||||
return errors.New("invalid value definition: missing @type definition")
|
||||
return fmt.Errorf("invalid value definition: missing @type definition")
|
||||
}
|
||||
|
||||
t.V, err = qlTypeRegistry(aux.Type).Cast(aux.Value)
|
||||
|
||||
@@ -2,7 +2,6 @@ package automation
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
. "github.com/cortezaproject/corteza/server/pkg/expr"
|
||||
@@ -82,7 +81,7 @@ func (h rolesHandler) searchMembers(ctx context.Context, args *rolesSearchMember
|
||||
return
|
||||
}
|
||||
if rl == nil {
|
||||
return nil, errors.New("role not found")
|
||||
return nil, fmt.Errorf("role not found")
|
||||
}
|
||||
|
||||
// Get membership info
|
||||
@@ -119,7 +118,7 @@ func (h rolesHandler) eachMember(ctx context.Context, args *rolesEachMemberArgs)
|
||||
return
|
||||
}
|
||||
if rl == nil {
|
||||
return nil, errors.New("role not found")
|
||||
return nil, fmt.Errorf("role not found")
|
||||
}
|
||||
|
||||
// Get membership info
|
||||
@@ -157,7 +156,7 @@ func (h rolesHandler) addMember(ctx context.Context, args *rolesAddMemberArgs) (
|
||||
return
|
||||
}
|
||||
if role == nil {
|
||||
return errors.New("role not found")
|
||||
return fmt.Errorf("role not found")
|
||||
}
|
||||
|
||||
user, err := lookupUser(ctx, h.uSvc, &usersLookupArgs{
|
||||
@@ -172,7 +171,7 @@ func (h rolesHandler) addMember(ctx context.Context, args *rolesAddMemberArgs) (
|
||||
return
|
||||
}
|
||||
if role == nil {
|
||||
return errors.New("user not found")
|
||||
return fmt.Errorf("user not found")
|
||||
}
|
||||
|
||||
return h.rSvc.MemberAdd(ctx, role.ID, user.ID)
|
||||
@@ -190,7 +189,7 @@ func (h rolesHandler) removeMember(ctx context.Context, args *rolesRemoveMemberA
|
||||
return
|
||||
}
|
||||
if role == nil {
|
||||
return errors.New("role not found")
|
||||
return fmt.Errorf("role not found")
|
||||
}
|
||||
|
||||
user, err := lookupUser(ctx, h.uSvc, &usersLookupArgs{
|
||||
@@ -205,7 +204,7 @@ func (h rolesHandler) removeMember(ctx context.Context, args *rolesRemoveMemberA
|
||||
return
|
||||
}
|
||||
if role == nil {
|
||||
return errors.New("user not found")
|
||||
return fmt.Errorf("user not found")
|
||||
}
|
||||
|
||||
return h.rSvc.MemberRemove(ctx, role.ID, user.ID)
|
||||
|
||||
@@ -2,7 +2,6 @@ package automation
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
. "github.com/cortezaproject/corteza/server/pkg/expr"
|
||||
@@ -77,7 +76,7 @@ func (h usersHandler) searchMembership(ctx context.Context, args *usersSearchMem
|
||||
return
|
||||
}
|
||||
if u == nil {
|
||||
return nil, errors.New("user not found")
|
||||
return nil, fmt.Errorf("user not found")
|
||||
}
|
||||
|
||||
// Get the roles
|
||||
@@ -118,7 +117,7 @@ func (h usersHandler) checkMembership(ctx context.Context, args *usersCheckMembe
|
||||
return
|
||||
}
|
||||
if u == nil {
|
||||
return nil, errors.New("user not found")
|
||||
return nil, fmt.Errorf("user not found")
|
||||
}
|
||||
|
||||
// Get user membershio
|
||||
@@ -145,7 +144,7 @@ func (h usersHandler) checkMembership(ctx context.Context, args *usersCheckMembe
|
||||
return
|
||||
}
|
||||
if r == nil {
|
||||
return nil, errors.New("role not found")
|
||||
return nil, fmt.Errorf("role not found")
|
||||
}
|
||||
|
||||
// Check if there
|
||||
|
||||
@@ -2,7 +2,7 @@ package renderer
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/cortezaproject/corteza/server/pkg/options"
|
||||
@@ -45,7 +45,7 @@ func (r *renderer) Render(ctx context.Context, pl *RendererPayload) (io.ReadSeek
|
||||
}
|
||||
}
|
||||
|
||||
return nil, errors.New("rendering failed: driver not found")
|
||||
return nil, fmt.Errorf("rendering failed: driver not found")
|
||||
}
|
||||
|
||||
func (r *renderer) Drivers() []DriverDefinition {
|
||||
|
||||
@@ -13,11 +13,8 @@ import (
|
||||
"github.com/cortezaproject/corteza/server/system/service"
|
||||
"github.com/cortezaproject/corteza/server/system/service/event"
|
||||
"github.com/cortezaproject/corteza/server/system/types"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var _ = errors.Wrap
|
||||
|
||||
type (
|
||||
Application struct {
|
||||
application applicationService
|
||||
|
||||
@@ -12,11 +12,8 @@ import (
|
||||
"github.com/cortezaproject/corteza/server/system/rest/request"
|
||||
"github.com/cortezaproject/corteza/server/system/service"
|
||||
"github.com/cortezaproject/corteza/server/system/types"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var _ = errors.Wrap
|
||||
|
||||
type (
|
||||
attachmentPayload struct {
|
||||
*types.Attachment
|
||||
@@ -40,7 +37,7 @@ func (Attachment) New() *Attachment {
|
||||
|
||||
func (ctrl Attachment) Read(ctx context.Context, r *request.AttachmentRead) (interface{}, error) {
|
||||
if !auth.GetIdentityFromContext(ctx).Valid() {
|
||||
return nil, errors.New("Unauthorized")
|
||||
return nil, fmt.Errorf("Unauthorized")
|
||||
}
|
||||
|
||||
a, err := ctrl.attachment.FindByID(ctx, r.AttachmentID)
|
||||
@@ -49,7 +46,7 @@ func (ctrl Attachment) Read(ctx context.Context, r *request.AttachmentRead) (int
|
||||
|
||||
func (ctrl Attachment) Delete(ctx context.Context, r *request.AttachmentDelete) (interface{}, error) {
|
||||
if !auth.GetIdentityFromContext(ctx).Valid() {
|
||||
return nil, errors.New("Unauthorized")
|
||||
return nil, fmt.Errorf("Unauthorized")
|
||||
}
|
||||
|
||||
_, err := ctrl.attachment.FindByID(ctx, r.AttachmentID)
|
||||
@@ -83,19 +80,19 @@ func (ctrl Attachment) isAccessible(kind string, attachmentID, userID uint64, si
|
||||
}
|
||||
|
||||
if signature == "" {
|
||||
return errors.New("Unauthorized")
|
||||
return fmt.Errorf("Unauthorized")
|
||||
}
|
||||
|
||||
if userID == 0 {
|
||||
return errors.New("missing or invalid user ID")
|
||||
return fmt.Errorf("missing or invalid user ID")
|
||||
}
|
||||
|
||||
if attachmentID == 0 {
|
||||
return errors.New("missing or invalid attachment ID")
|
||||
return fmt.Errorf("missing or invalid attachment ID")
|
||||
}
|
||||
|
||||
if !auth.DefaultSigner.Verify(signature, userID, attachmentID) {
|
||||
return errors.New("missing or invalid signature")
|
||||
return fmt.Errorf("missing or invalid signature")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -8,11 +8,8 @@ import (
|
||||
"github.com/cortezaproject/corteza/server/system/rest/request"
|
||||
"github.com/cortezaproject/corteza/server/system/service"
|
||||
"github.com/cortezaproject/corteza/server/system/types"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var _ = errors.Wrap
|
||||
|
||||
type (
|
||||
Auth struct {
|
||||
settings *types.AppSettings
|
||||
|
||||
@@ -9,11 +9,8 @@ import (
|
||||
"github.com/cortezaproject/corteza/server/system/rest/request"
|
||||
"github.com/cortezaproject/corteza/server/system/service"
|
||||
"github.com/cortezaproject/corteza/server/system/types"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var _ = errors.Wrap
|
||||
|
||||
type (
|
||||
AuthClient struct {
|
||||
authClient authClientService
|
||||
|
||||
@@ -7,11 +7,8 @@ import (
|
||||
"github.com/cortezaproject/corteza/server/pkg/corredor"
|
||||
"github.com/cortezaproject/corteza/server/system/rest/request"
|
||||
"github.com/cortezaproject/corteza/server/system/service/event"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var _ = errors.Wrap
|
||||
|
||||
type (
|
||||
Automation struct{}
|
||||
)
|
||||
|
||||
@@ -16,11 +16,8 @@ import (
|
||||
"github.com/cortezaproject/corteza/server/system/service"
|
||||
"github.com/cortezaproject/corteza/server/system/types"
|
||||
"github.com/modern-go/reflect2"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var _ = errors.Wrap
|
||||
|
||||
type (
|
||||
DalConnection struct {
|
||||
svc connectionService
|
||||
|
||||
@@ -8,11 +8,8 @@ import (
|
||||
|
||||
"github.com/cortezaproject/corteza/server/pkg/dal"
|
||||
"github.com/cortezaproject/corteza/server/system/rest/request"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var _ = errors.Wrap
|
||||
|
||||
type (
|
||||
DalDriver struct{}
|
||||
|
||||
|
||||
@@ -8,12 +8,9 @@ import (
|
||||
"github.com/cortezaproject/corteza/server/system/rest/request"
|
||||
"github.com/cortezaproject/corteza/server/system/service"
|
||||
"github.com/cortezaproject/corteza/server/system/types"
|
||||
"github.com/pkg/errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
var _ = errors.Wrap
|
||||
|
||||
type (
|
||||
Reminder struct {
|
||||
reminder service.ReminderService
|
||||
|
||||
@@ -9,11 +9,8 @@ import (
|
||||
"github.com/cortezaproject/corteza/server/system/rest/request"
|
||||
"github.com/cortezaproject/corteza/server/system/service"
|
||||
"github.com/cortezaproject/corteza/server/system/types"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var _ = errors.Wrap
|
||||
|
||||
type (
|
||||
Report struct {
|
||||
report reportService
|
||||
|
||||
@@ -11,11 +11,8 @@ import (
|
||||
"github.com/cortezaproject/corteza/server/system/service"
|
||||
"github.com/cortezaproject/corteza/server/system/service/event"
|
||||
"github.com/cortezaproject/corteza/server/system/types"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var _ = errors.Wrap
|
||||
|
||||
type (
|
||||
Role struct {
|
||||
role service.RoleService
|
||||
|
||||
@@ -12,11 +12,8 @@ import (
|
||||
"github.com/cortezaproject/corteza/server/system/rest/request"
|
||||
"github.com/cortezaproject/corteza/server/system/service"
|
||||
"github.com/cortezaproject/corteza/server/system/types"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var _ = errors.Wrap
|
||||
|
||||
type (
|
||||
SensitivityLevel struct {
|
||||
svc sensitivityLevelService
|
||||
|
||||
@@ -2,12 +2,9 @@ package rest
|
||||
|
||||
import (
|
||||
"github.com/cortezaproject/corteza/server/pkg/auth"
|
||||
"github.com/pkg/errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var _ = errors.Wrap
|
||||
|
||||
type Sink struct {
|
||||
svc interface {
|
||||
ProcessRequest(w http.ResponseWriter, r *http.Request)
|
||||
|
||||
@@ -4,11 +4,8 @@ import (
|
||||
"context"
|
||||
"github.com/cortezaproject/corteza/server/system/rest/request"
|
||||
"github.com/cortezaproject/corteza/server/system/service"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var _ = errors.Wrap
|
||||
|
||||
type (
|
||||
Stats struct {
|
||||
svc statsService
|
||||
|
||||
@@ -15,11 +15,8 @@ import (
|
||||
"github.com/cortezaproject/corteza/server/system/rest/request"
|
||||
"github.com/cortezaproject/corteza/server/system/service"
|
||||
"github.com/cortezaproject/corteza/server/system/types"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var _ = errors.Wrap
|
||||
|
||||
type (
|
||||
Template struct {
|
||||
renderer service.TemplateService
|
||||
|
||||
@@ -25,12 +25,9 @@ import (
|
||||
"github.com/cortezaproject/corteza/server/system/service/event"
|
||||
"github.com/cortezaproject/corteza/server/system/types"
|
||||
"github.com/gabriel-vasile/mimetype"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
var _ = errors.Wrap
|
||||
|
||||
type (
|
||||
User struct {
|
||||
user service.UserService
|
||||
|
||||
@@ -3,7 +3,7 @@ package service
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"sort"
|
||||
@@ -50,7 +50,7 @@ func (svc *apigwProfiler) Hits(ctx context.Context, filter types.ApigwProfilerFi
|
||||
filter.Path = string(uDec)
|
||||
|
||||
if filter.Path == "" && filter.Hit == "" {
|
||||
err = errors.New("fetching all hits (no route and hit specified) not supported")
|
||||
err = fmt.Errorf("fetching all hits (no route and hit specified) not supported")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package service
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"image"
|
||||
"image/gif"
|
||||
"io"
|
||||
@@ -17,7 +18,6 @@ import (
|
||||
"github.com/cortezaproject/corteza/server/system/types"
|
||||
"github.com/disintegration/imaging"
|
||||
"github.com/edwvee/exiffix"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -207,7 +207,7 @@ func (svc attachment) create(ctx context.Context, name string, size int64, fh io
|
||||
att.CreatedAt = *now()
|
||||
|
||||
if svc.files == nil {
|
||||
return errors.New("cannot create attachment: store handler not set")
|
||||
return fmt.Errorf("cannot create attachment: store handler not set")
|
||||
}
|
||||
|
||||
if size == 0 {
|
||||
@@ -290,7 +290,7 @@ func (svc attachment) processImage(original io.ReadSeeker, att *types.Attachment
|
||||
}
|
||||
|
||||
if format, err = imaging.FormatFromExtension(att.Meta.Original.Extension); err != nil {
|
||||
return errors.Wrapf(err, "could not get format from extension '%s'", att.Meta.Original.Extension)
|
||||
return fmt.Errorf("could not get format from extension '%s'", att.Meta.Original.Extension, err)
|
||||
}
|
||||
|
||||
previewFormat = format
|
||||
@@ -298,7 +298,7 @@ func (svc attachment) processImage(original io.ReadSeeker, att *types.Attachment
|
||||
if imaging.JPEG == format {
|
||||
// Rotate image if needed
|
||||
// if preview, _, err = exiffix.Decode(original); err != nil {
|
||||
// return errors.Wrapf(err, "Could not decode EXIF from JPEG")
|
||||
// return fmt.Errorf("Could not decode EXIF from JPEG", err)
|
||||
// }
|
||||
preview, _, _ = exiffix.Decode(original)
|
||||
}
|
||||
@@ -311,7 +311,7 @@ func (svc attachment) processImage(original io.ReadSeeker, att *types.Attachment
|
||||
// Use first image for the preview
|
||||
preview = cfg.Image[0]
|
||||
} else {
|
||||
return errors.Wrapf(err, "could not decode gif config")
|
||||
return fmt.Errorf("could not decode gif config", err)
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -326,7 +326,7 @@ func (svc attachment) processImage(original io.ReadSeeker, att *types.Attachment
|
||||
// other cases are handled here
|
||||
if preview == nil {
|
||||
if preview, err = imaging.Decode(original); err != nil {
|
||||
return errors.Wrapf(err, "could not decode original image")
|
||||
return fmt.Errorf("could not decode original image", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -344,13 +344,13 @@ func (svc *auth) InternalSignUp(ctx context.Context, input *types.User, password
|
||||
}
|
||||
|
||||
// if !svc.settings.internalSignUpSendEmailOnExisting {
|
||||
// return nil,errors.Wrap(err, "user with this email already exists")
|
||||
// return nil,fmt.Errorf("user with this email already exists", err)
|
||||
// }
|
||||
|
||||
// User already exists, but we're nice and we'll send this user an
|
||||
// email that will help him to login
|
||||
// if !u.Valid() {
|
||||
// return nil,errors.New("could not validate the user")
|
||||
// return nil,fmt.Errorf("could not validate the user")
|
||||
// }
|
||||
//
|
||||
// return nil,nil
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -544,7 +544,7 @@ var _ KVDecoder = &ExternalAuthProviderSet{}
|
||||
|
||||
func (eap ExternalAuthProvider) EncodeKV() (vv SettingValueSet, err error) {
|
||||
if eap.Handle == "" {
|
||||
return nil, errors.New("cannot encode external auth provider without handle")
|
||||
return nil, fmt.Errorf("cannot encode external auth provider without handle")
|
||||
}
|
||||
var (
|
||||
prefix = "auth.external.providers." + eap.Handle + "."
|
||||
|
||||
@@ -5,8 +5,6 @@ import (
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -33,11 +31,11 @@ type (
|
||||
func DecodeKV(kv SettingsKV, dst interface{}, pp ...string) (err error) {
|
||||
valueOf := reflect.ValueOf(dst)
|
||||
if valueOf.Kind() != reflect.Ptr {
|
||||
return errors.New("expecting a pointer, not a value")
|
||||
return fmt.Errorf("expecting a pointer, not a value")
|
||||
}
|
||||
|
||||
if valueOf.IsNil() {
|
||||
return errors.New("nil pointer passed")
|
||||
return fmt.Errorf("nil pointer passed")
|
||||
}
|
||||
|
||||
var prefix string
|
||||
|
||||
@@ -7,8 +7,6 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/cortezaproject/corteza/server/compose/types"
|
||||
)
|
||||
|
||||
@@ -68,7 +66,7 @@ func AssertNoErrors(rsp *http.Response, _ *http.Request) (err error) {
|
||||
|
||||
// Asserts that all expected errors are returned
|
||||
//
|
||||
// Compares each error by Kind, Message and Meta.field
|
||||
// # Compares each error by Kind, Message and Meta.field
|
||||
//
|
||||
// Note: This assertion always expects errors!
|
||||
func AssertRecordValueError(exp ...*types.RecordValueError) assertFn {
|
||||
@@ -125,11 +123,11 @@ func AssertError(expectedError string) assertFn {
|
||||
}
|
||||
|
||||
if tmp.Error.Message == "" {
|
||||
return errors.Errorf("No error, expecting: %v", expectedError)
|
||||
return fmt.Errorf("No error, expecting: %v", expectedError)
|
||||
}
|
||||
|
||||
if expectedError != tmp.Error.Message {
|
||||
return errors.Errorf("Expecting error %v, got: %v", expectedError, tmp.Error.Message)
|
||||
return fmt.Errorf("Expecting error %v, got: %v", expectedError, tmp.Error.Message)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -146,7 +144,7 @@ func AssertBody(expected string) assertFn {
|
||||
|
||||
got := strings.Trim(string(bb), " \n")
|
||||
if expected != got {
|
||||
return errors.Errorf("Expecting: %v, got: %v", expected, got)
|
||||
return fmt.Errorf("Expecting: %v, got: %v", expected, got)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -161,11 +159,11 @@ func AssertErrorP(expectedError string) assertFn {
|
||||
}
|
||||
|
||||
if tmp.Error.Message == "" {
|
||||
return errors.Errorf("No error, expecting error with: %v", expectedError)
|
||||
return fmt.Errorf("No error, expecting error with: %v", expectedError)
|
||||
}
|
||||
|
||||
if !strings.Contains(tmp.Error.Message, expectedError) {
|
||||
return errors.Errorf("Expecting error with %v, got: %v", expectedError, tmp.Error.Message)
|
||||
return fmt.Errorf("Expecting error with %v, got: %v", expectedError, tmp.Error.Message)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user