: safe-base64-decode ( String -- String )
    encoding.base64-decode [
        # Success - string is on stack
    ] [
        drop "ERROR"
    ] if
;

: safe-hex-decode ( String -- String )
    encoding.hex-decode [
        # Success - string is on stack
    ] [
        drop "ERROR"
    ] if
;

: test-errors ( -- )
    "SGVsbG8=" safe-base64-decode
    "Hello" test.assert-eq

    "Not!!!Valid" safe-base64-decode
    "ERROR" test.assert-eq

    "48656c6c6f" safe-hex-decode
    "Hello" test.assert-eq

    "xyz123" safe-hex-decode
    "ERROR" test.assert-eq

    "123" safe-hex-decode
    "ERROR" test.assert-eq
;
