{"record":{"id":"b08151378158bfcc","repo":"kestra-io/kestra","slug":"need-a-string-to-hash","errorCode":null,"errorMessage":"Need a string to hash\n","messagePattern":"Need a string to hash\n","errorType":"validation","errorClass":"PebbleException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/io/kestra/core/runners/pebble/filters/ShaBaseFilter.java","lineNumber":41,"sourceCode":"    }\n\n    @Override\n    public Object apply(Object input, Map<String, Object> args, PebbleTemplate self,\n        EvaluationContext context, int lineNumber) throws PebbleException {\n        if (input == null) {\n            return null;\n        }\n\n        if (input instanceof String str) {\n            try {\n                MessageDigest digest = MessageDigest.getInstance(algorithm);\n                byte[] encodedHash = digest.digest((str).getBytes(StandardCharsets.UTF_8));\n                return bytesToHex(encodedHash);\n            } catch (Exception e) {\n                throw new PebbleException(e, \"Hashing exception encountered\\n\", lineNumber, self.getName());\n            }\n        } else {\n            throw new PebbleException(null, \"Need a string to hash\\n\", lineNumber, self.getName());\n        }\n    }\n\n    private static String bytesToHex(byte[] bytes) {\n        StringBuilder hexString = new StringBuilder(2 * bytes.length);\n        for (byte aByte : bytes) {\n            String hex = Integer.toHexString(0xff & aByte);\n            if (hex.length() == 1) {\n                hexString.append('0');\n            }\n            hexString.append(hex);\n        }\n        return hexString.toString();\n    }\n\n}\n","sourceCodeStart":23,"sourceCodeEnd":58,"githubUrl":"https://github.com/kestra-io/kestra/blob/823fada9274c4f9c251ea0a516460a4f7d958032/core/src/main/java/io/kestra/core/runners/pebble/filters/ShaBaseFilter.java#L23-L58","documentation":"Thrown by the SHA filter family (sha1, sha256, etc.) when the input to the filter is not a String. MessageDigest operates on bytes, and the filter only accepts String inputs (encoded as UTF-8); any other type (Number, Boolean, Map, List, custom object) is rejected up front with the actual class in the message.","triggerScenarios":"Calling `{{ 42 | sha256 }}`, `{{ someMap | sha256 }}`, or `{{ outputs.task.value | sha256 }}` where the value is a non-String type. Commonly happens when an upstream output is already typed (INTEGER/JSON object) rather than a string.","commonSituations":"Hashing a numeric ID without first stringifying; hashing a JSON object by accident (user intended to hash its serialized form).","solutions":["Stringify before hashing: `{{ myval | toString | sha256 }}` (or rely on string interpolation `{{ myval ~ \"\" | sha256 }}` if appropriate).","For JSON content, serialize explicitly before hashing.","Check the upstream output type and adjust the filter chain."],"exampleFix":"# before\n{{ outputs.gen.id | sha256 }}\n# after\n{{ outputs.gen.id | toString | sha256 }}","handlingStrategy":"type-guard","validationCode":"# Stringify non-string inputs before hashing:\n{% if myval is string %}\n  {{ myval | sha256 }}\n{% else %}\n  {{ myval | toString | sha256 }}\n{% endif %}","typeGuard":"# Pebble: `is string` narrows to the accepted type.\n# Use `is number`/`is iterable` to branch other shapes before hashing.","tryCatchPattern":null,"preventionTips":["Check the upstream output type before applying `| sha256`.","Stringify explicitly with `| toString` when the value may be non-string.","For JSON objects, serialise to a stable string form before hashing."],"tags":["pebble-filter","sha","hashing","type-mismatch","string"],"backgroundTag":null,"analyzedSha":"823fada9274c4f9c251ea0a516460a4f7d958032","analyzedAt":"2026-08-14T06:15:17.947Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}