MCPcopy Create free account
hub / github.com/Effect-TS/effect / decodeFailure

Function decodeFailure

packages/effect/src/encoding/Hex.ts:229–240  ·  view source on GitHub ↗
(
  str: string,
  byteLength: number = encoder.encode(str).length
)

Source from the content-addressed store, hash-verified

227// The odd-length message reports the UTF-8 byte length, so non-ASCII input
228// whose UTF-8 encoding has an even length reports "Invalid input" instead.
229const decodeFailure = (
230 str: string,
231 byteLength: number = encoder.encode(str).length
232): Result.Result<never, EncodingError> =>
233 Result.fail(
234 new EncodingError({
235 module: "Hex",
236 kind: "Decode",
237 input: str,
238 message: byteLength % 2 !== 0 ? `Length must be a multiple of 2, but is ${byteLength}` : "Invalid input"
239 })
240 )
241
242/**
243 * Decodes a hexadecimal string into a UTF-8 string safely.

Callers 2

decodeFunction · 0.85

Calls 2

encodeMethod · 0.80
failMethod · 0.65

Tested by

no test coverage detected