Skip to content

Commit

Permalink
Fail if cache creation fails
Browse files Browse the repository at this point in the history
  • Loading branch information
travisbrown committed Jul 28, 2021
1 parent 42e4c2d commit 46f8874
Showing 1 changed file with 3 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.dhallj.imports

import java.nio.file.{Files, Path, Paths}

import cats.Applicative
import cats.effect.Async
import cats.implicits._
import java.nio.file.{Files, Path, Paths}
import org.dhallj.core.DhallException.ResolutionFailure

trait ImportCache[F[_]] {
def get(key: Array[Byte]): F[Option[Array[Byte]]]
Expand Down Expand Up @@ -73,18 +73,11 @@ object ImportCache {
if (isWindows)
makeCacheFromEnvVar("LOCALAPPDATA", "")
else makeCacheFromEnvVar("HOME", ".cache")
cache <- cacheO.fold[F[ImportCache[F]]](F.as(warnCacheNotCreated, new NoopImportCache[F]))(F.pure)
cache <- F.fromOption(cacheO, new ResolutionFailure("Failed to create cache"))
} yield cache

def isWindows = System.getProperty("os.name").toLowerCase.contains("windows")

def warnCacheNotCreated: F[Unit] =
F.delay(
println(
"WARNING: failed to create cache at either $XDG_CACHE_HOME}/dhall or $HOME/.cache/dhall. Are these locations writable?"
)
)

for {
xdgCache <- makeCacheFromEnvVar("XDG_CACHE_HOME", "")
cache <- xdgCache.fold(backupCache)(F.pure)
Expand Down

0 comments on commit 46f8874

Please sign in to comment.