{"record":{"id":"34b27e87bbcafe3e","repo":"grafana/k6","slug":"failed-to-extract-algorithm-w","errorCode":null,"errorMessage":"failed to extract algorithm: %w","messagePattern":"failed to extract algorithm: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/webcrypto/jwk.go","lineNumber":86,"sourceCode":"\n// exportSymmetricJWK exports a symmetric key as a map of JWK key parameters.\nfunc exportSymmetricJWK(key *CryptoKey) (*JsonWebKey, error) {\n\trawKey, ok := key.handle.([]byte)\n\tif !ok {\n\t\treturn nil, errors.New(\"key's handle isn't a byte slice\")\n\t}\n\n\t// wrap result into the object that is expected to be returned\n\texported := &JsonWebKey{}\n\n\texported.Set(\"k\", base64URLEncode(rawKey))\n\texported.Set(\"kty\", JWKOctKeyType)\n\texported.Set(\"ext\", key.Extractable)\n\texported.Set(\"key_ops\", key.Usages)\n\n\talgV, err := extractAlg(key.Algorithm, len(rawKey))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to extract algorithm: %w\", err)\n\t}\n\texported.Set(\"alg\", algV)\n\n\treturn exported, nil\n}\n\nfunc extractAlg(inAlg any, keyLen int) (string, error) {\n\tswitch alg := inAlg.(type) {\n\tcase hasHash:\n\t\tv := alg.hash()\n\t\tif len(v) < 4 {\n\t\t\treturn \"\", errors.New(\"length of hash algorithm is less than 4: \" + v)\n\t\t}\n\t\treturn \"HS\" + v[4:], nil\n\tcase hasAlg:\n\t\tv := alg.alg()\n\t\tif len(v) < 4 {\n\t\t\treturn \"\", errors.New(\"length of named algorithm is less than 4: \" + v)","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/grafana/k6/blob/8d06114777191d21ef885d05c5f8aa9e1ed838ae/internal/js/modules/k6/webcrypto/jwk.go#L68-L104","documentation":"Returned by exportSymmetricJWK (exporting an HMAC or AES key as JWK) when the internal extractAlg helper fails to derive the JWK `alg` string from the key's algorithm object. The wrapped error typically comes from the algorithm name being too short to strip its prefix, meaning the CryptoKey holds a malformed or non-standard algorithm representation — usually a sign the key was created/imported with inconsistent algorithm parameters.","triggerScenarios":"Thrown at internal/js/modules/k6/webcrypto/jwk.go:85 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Re-import or re-generate the key using a standard algorithm name (e.g. 'AES-GCM', 'HMAC', 'AES-CBC')","Inspect the wrapped error message to see which algorithm component was rejected"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"8d06114777191d21ef885d05c5f8aa9e1ed838ae","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}