Skip to content

Commit

Permalink
k6/execution: use common.NewInitContextError
Browse files Browse the repository at this point in the history
  • Loading branch information
mstoykov committed Apr 25, 2024
1 parent d28d6f1 commit 10e9a81
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions js/modules/k6/execution/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,15 @@ func (mi *ModuleInstance) newScenarioInfo() (*goja.Object, error) {
return newInfoObj(rt, si)
}

//nolint:lll,gochecknoglobals
var instanceInfoInitContextErr = common.NewInitContextError("getting instance information in the init context is not supported")

// newInstanceInfo returns a goja.Object with property accessors to retrieve
// information about the local instance stats.
func (mi *ModuleInstance) newInstanceInfo() (*goja.Object, error) {
es := lib.GetExecutionState(mi.vu.Context())
if es == nil {
return nil, errors.New("getting instance information in the init context is not supported")
return nil, instanceInfoInitContextErr
}
rt := mi.vu.Runtime()

Expand All @@ -157,6 +160,9 @@ func (mi *ModuleInstance) newInstanceInfo() (*goja.Object, error) {
return newInfoObj(rt, ti)
}

//nolint:gochecknoglobals
var testInfoInitContextErr = common.NewInitContextError("getting test options in the init context is not supported")

// newTestInfo returns a goja.Object with property accessors to retrieve
// information and control execution of the overall test run.
func (mi *ModuleInstance) newTestInfo() (*goja.Object, error) {
Expand All @@ -178,7 +184,7 @@ func (mi *ModuleInstance) newTestInfo() (*goja.Object, error) {
"options": func() interface{} {
vuState := mi.vu.State()
if vuState == nil {
common.Throw(rt, fmt.Errorf("getting test options in the init context is not supported"))
common.Throw(rt, testInfoInitContextErr)
}
if optionsObject == nil {
opts, err := optionsAsObject(rt, vuState.Options)
Expand All @@ -194,12 +200,15 @@ func (mi *ModuleInstance) newTestInfo() (*goja.Object, error) {
return newInfoObj(rt, ti)
}

//nolint:gochecknoglobals
var vuInfoInitContextErr = common.NewInitContextError("getting VU information in the init context is not supported")

// newVUInfo returns a goja.Object with property accessors to retrieve
// information about the currently executing VU.
func (mi *ModuleInstance) newVUInfo() (*goja.Object, error) {
vuState := mi.vu.State()
if vuState == nil {
return nil, errors.New("getting VU information in the init context is not supported")
return nil, vuInfoInitContextErr
}
rt := mi.vu.Runtime()

Expand Down

0 comments on commit 10e9a81

Please sign in to comment.