Skip to content

Commit

Permalink
Merge branch 'version/0-41-0-RC1' into mitchell/dx-2198
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchell-as committed Sep 19, 2023
2 parents 1c26525 + 8e61f46 commit 816c7b7
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 47 deletions.
1 change: 0 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ jobs:
continue-on-error: ${{ github.event_name == 'schedule' }}
env:
ACTIVESTATE_VERBOSE: true
ACTIVESTATE_DEBUG_SERVICE_REQUESTS: true
INTEGRATION_TEST_USERNAME: ${{ secrets.INTEGRATION_TEST_USERNAME }}
INTEGRATION_TEST_PASSWORD: ${{ secrets.INTEGRATION_TEST_PASSWORD }}
INTEGRATION_TEST_TOKEN: ${{ secrets.INTEGRATION_TEST_TOKEN }}
Expand Down
3 changes: 2 additions & 1 deletion cmd/state-svc/internal/resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
configMediator "github.com/ActiveState/cli/internal/mediators/config"
"github.com/ActiveState/cli/internal/multilog"
"github.com/ActiveState/cli/internal/poller"
"github.com/ActiveState/cli/internal/rtutils/ptr"
"github.com/ActiveState/cli/internal/updater"
"github.com/ActiveState/cli/pkg/platform/authentication"
"github.com/ActiveState/cli/pkg/projectfile"
Expand Down Expand Up @@ -164,7 +165,7 @@ func (r *Resolver) Projects(ctx context.Context) ([]*graph.Project, error) {
func (r *Resolver) AnalyticsEvent(_ context.Context, category, action, source string, _label *string, dimensionsJson string) (*graph.AnalyticsEventResponse, error) {
defer func() { handlePanics(recover(), debug.Stack()) }()

logging.Debug("Analytics event resolver: %s - %s (%s)", category, action, source)
logging.Debug("Analytics event resolver: %s - %s: %s (%s)", category, action, ptr.From(_label, "NIL"), source)

label := ""
if _label != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/analytics/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ const CatShim = "shim"
// CatBuild is the event category used for headchef builds
const CatBuild = "build"

// CatRuntime is the event category used for debugging runtime setup and usage.
// CatRuntimeDebug is the event category used for debugging runtime setup and usage.
// It should only be used to help diagnose where errors and dropoffs may be happening.
const CatRuntime = "runtime-debug"
const CatRuntimeDebug = "runtime-debug"

// CatRuntimeUsage is the event category used for all runtime usage
const CatRuntimeUsage = "runtime-use"
Expand Down
12 changes: 7 additions & 5 deletions internal/locale/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"github.com/ActiveState/cli/internal/rtutils"
)

var _ ErrorLocalizer = &LocalizedError{}

// LocalizedError is an error that has the concept of user facing (localized) errors as well as whether an error is due
// to user input or not
type LocalizedError struct {
Expand All @@ -27,8 +29,8 @@ func (e *LocalizedError) Error() string {
return e.localized
}

// UserError is the user facing error message, it's the same as Error() but identifies it as being user facing
func (e *LocalizedError) LocalizedError() string {
// LocaleError is the user facing error message, it's the same as Error() but identifies it as being user facing
func (e *LocalizedError) LocaleError() string {
return e.localized
}

Expand Down Expand Up @@ -58,7 +60,7 @@ func (e *LocalizedError) AddTips(tips ...string) {
// ErrorLocalizer represents a localized error
type ErrorLocalizer interface {
error
LocalizedError() string
LocaleError() string
}

type AsError interface {
Expand Down Expand Up @@ -162,7 +164,7 @@ func JoinedErrorMessage(err error) string {
var message []string
for _, err := range UnpackError(err) {
if lerr, isLocaleError := err.(ErrorLocalizer); isLocaleError {
message = append(message, lerr.LocalizedError())
message = append(message, lerr.LocaleError())
}
}
if len(message) == 0 {
Expand All @@ -177,7 +179,7 @@ func JoinedErrorMessage(err error) string {

func ErrorMessage(err error) string {
if errr, ok := err.(ErrorLocalizer); ok {
return errr.LocalizedError()
return errr.LocaleError()
}
return err.Error()
}
Expand Down
31 changes: 22 additions & 9 deletions internal/locale/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,45 +109,54 @@ func TestUnwrapError(t *testing.T) {
errMulti := errs.Pack(errLocalized, errLocalized2, errPlain, errPlainWrapWithLocale, errLocaleWrapWithPlain)
errPlainWrappedMulti := errs.Wrap(errMulti, "wrapped plain error")

type customType struct{ *locale.LocalizedError }
errCustomTypedInner := locale.NewError("custom typed")
errCustomTyped := &customType{errCustomTypedInner}

tests := []struct {
name string
inError error
wantErrors []error
wantErrors []locale.ErrorLocalizer
}{
{
"Plain",
errPlain,
[]error{},
[]locale.ErrorLocalizer{},
},
{
"Localized",
errLocalized,
[]error{errLocalized},
[]locale.ErrorLocalizer{errLocalized},
},
{
"Localized wrapped with plain",
errLocaleWrapWithPlain,
[]error{errLocaleWrapWithPlain},
[]locale.ErrorLocalizer{errLocaleWrapWithPlain},
},
{
"Plain wrapped with localized",
errPlainWrapWithLocale,
[]error{errLocalizedForWrapWithLocale},
[]locale.ErrorLocalizer{errLocalizedForWrapWithLocale},
},
{
"Multi error",
errMulti,
[]error{errLocalized, errLocalized2, errLocalizedForWrapWithLocale, errLocaleWrapWithPlain},
[]locale.ErrorLocalizer{errLocalized, errLocalized2, errLocalizedForWrapWithLocale, errLocaleWrapWithPlain},
},
{
"Plain wrapped Multi error",
errPlainWrappedMulti,
[]error{errLocalized, errLocalized2, errLocalizedForWrapWithLocale, errLocaleWrapWithPlain},
[]locale.ErrorLocalizer{errLocalized, errLocalized2, errLocalizedForWrapWithLocale, errLocaleWrapWithPlain},
},
{
"Multi error with locale wrap",
errMultiWithLocaleWrap,
[]error{errLocalizedForWrapWithLocale},
[]locale.ErrorLocalizer{errLocalizedForWrapWithLocale},
},
{
"Custom typed",
errCustomTyped,
[]locale.ErrorLocalizer{errCustomTypedInner},
},
}
for _, tt := range tests {
Expand All @@ -159,7 +168,11 @@ func TestUnwrapError(t *testing.T) {
}

for n, wantErr := range tt.wantErrors {
if got[n].Error() != wantErr.Error() {
gotErr, ok := got[n].(locale.ErrorLocalizer)
if !ok {
t.Fatalf("Error is not localized, this shouldn't have happened since UnpackError should only return localized errors")
}
if gotErr.LocaleError() != wantErr.LocaleError() {
t.Errorf("Resulting error: %s, did not match: %s", got[n].Error(), wantErr.Error())
}
}
Expand Down
8 changes: 0 additions & 8 deletions pkg/cmdlets/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,6 @@ func ParseUserFacing(err error) (int, error) {
return code, nil
}

// If there is a user facing error in the error stack we want to ensure
// that is it forwarded to the user.
var userFacingError errs.UserFacingError
if errors.As(err, &userFacingError) {
logging.Debug("Returning user facing error, error stack: \n%s", errs.JoinMessage(err))
return code, &OutputError{userFacingError}
}

// If the error already has a marshalling function we do not want to wrap
// it again in the OutputError type.
if hasMarshaller {
Expand Down
9 changes: 6 additions & 3 deletions pkg/platform/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,14 @@ func newRuntime(target setup.Targeter, an analytics.Dispatcher, svcModel *model.

// New attempts to create a new runtime from local storage. If it fails with a NeedsUpdateError, Update() needs to be called to update the locally stored runtime.
func New(target setup.Targeter, an analytics.Dispatcher, svcm *model.SvcModel) (*Runtime, error) {
logging.Debug("Initializing runtime for: %s/%s@%s", target.Owner(), target.Name(), target.CommitUUID())

if strings.ToLower(os.Getenv(constants.DisableRuntime)) == "true" {
fmt.Fprintln(os.Stderr, locale.Tl("notice_runtime_disabled", "Skipping runtime setup because it was disabled by an environment variable"))
return &Runtime{disabled: true, target: target}, nil
}
recordAttempt(an, target)
an.Event(anaConsts.CatRuntime, anaConsts.ActRuntimeStart, &dimensions.Values{
an.Event(anaConsts.CatRuntimeDebug, anaConsts.ActRuntimeStart, &dimensions.Values{
Trigger: ptr.To(target.Trigger().String()),
Headless: ptr.To(strconv.FormatBool(target.Headless())),
CommitID: ptr.To(target.CommitUUID().String()),
Expand All @@ -86,7 +88,7 @@ func New(target setup.Targeter, an analytics.Dispatcher, svcm *model.SvcModel) (

r, err := newRuntime(target, an, svcm)
if err == nil {
an.Event(anaConsts.CatRuntime, anaConsts.ActRuntimeCache, &dimensions.Values{
an.Event(anaConsts.CatRuntimeDebug, anaConsts.ActRuntimeCache, &dimensions.Values{
CommitID: ptr.To(target.CommitUUID().String()),
})
}
Expand All @@ -105,6 +107,7 @@ func (r *Runtime) Target() setup.Targeter {
// This function is usually called, after New() returned with a NeedsUpdateError
func (r *Runtime) Update(auth *authentication.Auth, eventHandler events.Handler) (rerr error) {
if r.disabled {
logging.Debug("Skipping update as it is disabled")
return nil // nothing to do
}

Expand Down Expand Up @@ -225,7 +228,7 @@ func (r *Runtime) recordCompletion(err error) {
message = errs.JoinMessage(err)
}

r.analytics.Event(anaConsts.CatRuntime, action, &dimensions.Values{
r.analytics.Event(anaConsts.CatRuntimeDebug, action, &dimensions.Values{
CommitID: ptr.To(r.target.CommitUUID().String()),
// Note: ProjectID is set by state-svc since ProjectNameSpace is specified.
ProjectNameSpace: ptr.To(ns.String()),
Expand Down
4 changes: 2 additions & 2 deletions pkg/platform/runtime/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ func (s *Setup) fetchAndInstallArtifactsFromBuildPlan(installFunc artifactInstal

// send analytics build event, if a new runtime has to be built in the cloud
if buildResult.BuildStatus == bpModel.Started {
s.analytics.Event(anaConsts.CatRuntime, anaConsts.ActRuntimeBuild, dimensions)
s.analytics.Event(anaConsts.CatRuntimeDebug, anaConsts.ActRuntimeBuild, dimensions)
}

changedArtifacts, err := buildplan.NewBaseArtifactChangesetByBuildPlan(buildResult.Build, false)
Expand Down Expand Up @@ -534,7 +534,7 @@ func (s *Setup) fetchAndInstallArtifactsFromBuildPlan(installFunc artifactInstal
// only send the download analytics event, if we have to install artifacts that are not yet installed
if len(artifactsToInstall) > 0 {
// if we get here, we download artifacts
s.analytics.Event(anaConsts.CatRuntime, anaConsts.ActRuntimeDownload, dimensions)
s.analytics.Event(anaConsts.CatRuntimeDebug, anaConsts.ActRuntimeDownload, dimensions)
}

err = s.installArtifactsFromBuild(buildResult, runtimeArtifacts, artifact.ArtifactIDsToMap(artifactsToInstall), downloadablePrebuiltResults, setup, installFunc, logFilePath)
Expand Down
Loading

0 comments on commit 816c7b7

Please sign in to comment.