Skip to content

Commit 526d057

Browse files
committed
return an error instead of throwing exception
1 parent 38aa841 commit 526d057

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

examples/example-tls.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
// It will have to be refactored.
33

44
import sql from "k6/x/sql";
5-
import { loadTLS, addTLS, default as driver } from "k6/x/sql/driver/mysql";
5+
import { loadTLS, addTLS, TLS_1_2, default as driver } from "k6/x/sql/driver/mysql";
66

7-
loadTLS({
7+
const err = loadTLS({
88
enableTLS: true,
99
insecureSkipTLSverify: true,
10-
minVersion: driver.TLS_1_2,
11-
// Possible values: sql.TLS_1_0, sql.TLS_1_1, sql.TLS_1_2, sql.TLS_1_3
10+
minVersion: TLS_1_2,
11+
// Possible values: TLS_1_0, TLS_1_1, TLS_1_2, TLS_1_3
1212
caCertFile: "ca.pem",
1313
clientCertFile: "client-cert.pem",
1414
clientKeyFile: "client-key.pem",

tls.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"strings"
1313

1414
"github.com/go-sql-driver/mysql"
15-
"go.k6.io/k6/js/common"
1615
"go.k6.io/k6/lib/netext"
1716
)
1817

@@ -24,7 +23,7 @@ var supportedTLSVersions = map[string]uint16{ //nolint: gochecknoglobals
2423
netext.TLS_1_3: tls.VersionTLS13,
2524
}
2625

27-
// tlsExports add TLS releated exports to name dexports.
26+
// tlsExports add TLS related exports to name exports.
2827
func (mod *module) tlsExports() {
2928
// TLS versions
3029
mod.exports.Named["TLS_1_0"] = netext.TLS_1_0
@@ -51,17 +50,16 @@ type TLSConfig struct {
5150

5251
// LoadTLS loads the TLS configuration for the SQL module.
5352
func (mod *module) LoadTLS(params map[string]interface{}) error {
54-
runtime := mod.vu.Runtime()
5553
var tlsConfig *TLSConfig
5654
if b, err := json.Marshal(params); err != nil {
57-
common.Throw(runtime, err)
55+
return err
5856
} else {
5957
if err := json.Unmarshal(b, &tlsConfig); err != nil {
60-
common.Throw(runtime, err)
58+
return err
6159
}
6260
}
6361
if _, ok := supportedTLSVersions[tlsConfig.MinVersion]; !ok {
64-
common.Throw(runtime, fmt.Errorf("unsupported TLS version: %s", tlsConfig.MinVersion))
62+
return fmt.Errorf("unsupported TLS version: %s", tlsConfig.MinVersion)
6563
}
6664
mod.tlsConfig = *tlsConfig
6765

0 commit comments

Comments
 (0)