grafana/k6 · error

%s failed: %w

Error message

%s failed: %w

What it means

A generic wrap ('%s' is the algorithm name, e.g. md5/sha256) raised inside the crypto module's buildInputsDigest pipeline — it catches failures while preparing the hasher inputs (converting the input value to bytes via common.ToBytes). It fires when the JS-provided input cannot be converted to a byte buffer (unsupported type), before any hashing occurs; the algorithm name merely labels the entry point (md4/md5/sha1/sha256/sha384/sha512) that was invoked.

Source

Thrown at internal/js/modules/k6/crypto/crypto.go:149

func (c *Crypto) ripemd160(input any, outputEncoding string) (any, error) {
	return c.buildInputsDigest("ripemd160", input, outputEncoding)
}

// createHash returns a Hasher instance that uses the given algorithm.
func (c *Crypto) createHash(algorithm string) *Hasher {
	hashfn := c.parseHashFunc(algorithm)
	return &Hasher{
		runtime: c.vu.Runtime(),
		hash:    hashfn(),
	}
}

// buildInputsDigest implements basic digest calculation for given algorithm and input/output
func (c *Crypto) buildInputsDigest(alg string, input any, outputEncoding string) (any, error) {
	hasher := c.createHash(alg)

	if err := hasher.Update(input); err != nil {
		return nil, fmt.Errorf("%s failed: %w", alg, err)
	}

	return hasher.Digest(outputEncoding)
}

// hexEncode returns a string with the hex representation of the provided byte
// array or ArrayBuffer.
func (c *Crypto) hexEncode(data any) (string, error) {
	d, err := common.ToBytes(data)
	if err != nil {
		return "", err
	}
	return hex.EncodeToString(d), nil
}

// createHMAC returns a new HMAC hash using the given algorithm and key.
func (c *Crypto) createHMAC(algorithm string, key any) (*Hasher, error) {
	h := c.parseHashFunc(algorithm)

View on GitHub (pinned to 01ffac6f24)

Solutions

  1. Pass a string, ArrayBuffer, or TypedArray as the input to the hash function
  2. Convert custom objects to a string/bytes before hashing
  3. Check the wrapped error for the exact input conversion failure
  4. Verify the output encoding argument is one of the supported values
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at internal/js/modules/k6/crypto/crypto.go:149 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18). Data as JSON: /api/errors/2f073cfd4081d0de. Report an issue: GitHub.