From 0dd01d1ac6b71ddae7379439fd06a104d8b2a5dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Miri=C4=87?= Date: Mon, 26 Apr 2021 11:39:23 +0200 Subject: [PATCH] Make init context error message consistent with other usage Resolves https://github.com/k6io/k6/pull/1863#discussion_r578223633 --- js/modules/k6/execution/execution.go | 6 +++--- js/runner_test.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/js/modules/k6/execution/execution.go b/js/modules/k6/execution/execution.go index 8f75a0c58e04..c01fb05a5c0c 100644 --- a/js/modules/k6/execution/execution.go +++ b/js/modules/k6/execution/execution.go @@ -39,7 +39,7 @@ func New() *Execution { func (e *Execution) GetVUStats(ctx context.Context) (map[string]interface{}, error) { vuState := lib.GetState(ctx) if vuState == nil { - return nil, errors.New("VU information can only be returned from an exported function") + return nil, errors.New("getting VU information in the init context is not supported") } scID, _ := vuState.GetScenarioVUID() @@ -57,7 +57,7 @@ func (e *Execution) GetVUStats(ctx context.Context) (map[string]interface{}, err func (e *Execution) GetScenarioStats(ctx context.Context) (map[string]interface{}, error) { ss := lib.GetScenarioState(ctx) if ss == nil { - return nil, errors.New("scenario information can only be returned from an exported function") + return nil, errors.New("getting scenario information in the init context is not supported") } progress, _ := ss.ProgressFn() @@ -79,7 +79,7 @@ func (e *Execution) GetScenarioStats(ctx context.Context) (map[string]interface{ func (e *Execution) GetTestStats(ctx context.Context) (map[string]interface{}, error) { es := lib.GetExecutionState(ctx) if es == nil { - return nil, errors.New("test information can only be returned from an exported function") + return nil, errors.New("getting test information in the init context is not supported") } out := map[string]interface{}{ diff --git a/js/runner_test.go b/js/runner_test.go index 8149a04b4467..34e647c631c6 100644 --- a/js/runner_test.go +++ b/js/runner_test.go @@ -2039,7 +2039,7 @@ func TestExecutionStats(t *testing.T) { {"vu_err", ` var exec = require('k6/execution'); exec.getVUStats(); - `, "VU information can only be returned from an exported function"}, + `, "getting VU information in the init context is not supported"}, {"scenario_ok", ` var exec = require('k6/execution'); var sleep = require('k6').sleep; @@ -2057,7 +2057,7 @@ func TestExecutionStats(t *testing.T) { {"scenario_err", ` var exec = require('k6/execution'); exec.getScenarioStats(); - `, "scenario information can only be returned from an exported function"}, + `, "getting scenario information in the init context is not supported"}, {"test_ok", ` var exec = require('k6/execution'); @@ -2071,7 +2071,7 @@ func TestExecutionStats(t *testing.T) { {"test_err", ` var exec = require('k6/execution'); exec.getTestStats(); - `, "test information can only be returned from an exported function"}, + `, "getting test information in the init context is not supported"}, } for _, tc := range testCases {