Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

fromBytes throws exceptions instead of returning the error inside the Maybe ValidationFailure #312

@jship

Description

@jship

The following program throws a ByteOutOfBound exception instead of providing the error in the Maybe ValidationError in the triple returned by fromBytes.

#!/usr/bin/env stack
-- stack script --resolver lts-8.17 --package foundation
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
module Main where

import Control.Monad
import Foundation
import Foundation.String
import Foundation.String.ASCII
import Foreign.C.Types

printString :: Encoding -> UArray Word8 -> IO ()
printString enc bytes = do
  -- fromBytes :: Encoding -> UArray Word8 -> (String, Maybe ValidationFailure, UArray Word8)
  let (string, minvalid, rest) = fromBytes enc bytes
  putStrLn string
  case minvalid of
    Nothing -> putStrLn "Valid!"
    (Just vf) -> putStrLn "Invalid!"
  when (null rest) $ do
    putStrLn "rest is empty"
  unless (null rest) $ do
    putStrLn "rest is not empty"

main = printString ASCII7 (fromList [0xff])
strings: ByteOutOfBound 255

Metadata

Metadata

Assignees

No one assigned

    Labels

    BBugT - arrayaffect type ArraysT - stringAffect type Strings

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions