namespace StorageExperiment

import System.*
import System.Result.*
import System.Storage.Path


func RequirePath(text: string) -> Path {
    return match Path.Parse(text) {
        Ok(let path) => path
        Failure(_) => {
            Panic("Invalid sample path")
            // Fault does not yet have compiler-visible non-returning semantics.
            RequirePath("/")
        }
    }
}

// Application bootstrap unwraps lookup while retaining only the public interface.
func RequireDirectory(provider: System.Storage.StorageProvider, path: System.Storage.Path) -> System.Storage.Directory {
    return match provider.GetDirectory(path) {
        Ok(let directory) => directory
        Failure(let error) => {
            Panic(error.ToString())
            // Fault does not yet have compiler-visible non-returning semantics.
            RequireDirectory(provider, path)
        }
    }
}
