mirror of
https://github.com/enso-org/enso.git
synced 2024-12-23 07:01:55 +03:00
Log FS service failures (#10562)
Without the original falure somehow logged, it is impossible to figure out the crashes.
This commit is contained in:
parent
73b12d0d60
commit
9e553397b6
@ -11,6 +11,7 @@ import org.enso.projectmanager.control.core.syntax._
|
|||||||
import org.enso.projectmanager.control.effect.syntax._
|
import org.enso.projectmanager.control.effect.syntax._
|
||||||
import org.enso.projectmanager.infrastructure.repository.ProjectRepositoryFactory
|
import org.enso.projectmanager.infrastructure.repository.ProjectRepositoryFactory
|
||||||
import org.enso.projectmanager.service.ProjectService
|
import org.enso.projectmanager.service.ProjectService
|
||||||
|
import org.slf4j.LoggerFactory
|
||||||
|
|
||||||
import java.io.{File, InputStream}
|
import java.io.{File, InputStream}
|
||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
@ -21,13 +22,16 @@ class FileSystemService[F[+_, +_]: Applicative: CovariantFlatMap: ErrorChannel](
|
|||||||
projectRepositoryFactory: ProjectRepositoryFactory[F]
|
projectRepositoryFactory: ProjectRepositoryFactory[F]
|
||||||
) extends FileSystemServiceApi[F] {
|
) extends FileSystemServiceApi[F] {
|
||||||
|
|
||||||
|
private lazy val logger = LoggerFactory.getLogger(this.getClass)
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** @inheritdoc */
|
||||||
override def exists(path: File): F[FileSystemServiceFailure, Boolean] =
|
override def exists(path: File): F[FileSystemServiceFailure, Boolean] =
|
||||||
fileSystem
|
fileSystem
|
||||||
.exists(path)
|
.exists(path)
|
||||||
.mapError(_ =>
|
.mapError { error =>
|
||||||
|
logger.warn("Failed to check if path exists", error)
|
||||||
FileSystemServiceFailure.FileSystem("Failed to check if path exists")
|
FileSystemServiceFailure.FileSystem("Failed to check if path exists")
|
||||||
)
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** @inheritdoc */
|
||||||
override def list(
|
override def list(
|
||||||
@ -35,9 +39,10 @@ class FileSystemService[F[+_, +_]: Applicative: CovariantFlatMap: ErrorChannel](
|
|||||||
): F[FileSystemServiceFailure, Seq[FileSystemEntry]] =
|
): F[FileSystemServiceFailure, Seq[FileSystemEntry]] =
|
||||||
fileSystem
|
fileSystem
|
||||||
.list(path)
|
.list(path)
|
||||||
.mapError(_ =>
|
.mapError { error =>
|
||||||
|
logger.warn("Failed to list directories", error)
|
||||||
FileSystemServiceFailure.FileSystem("Failed to list directories")
|
FileSystemServiceFailure.FileSystem("Failed to list directories")
|
||||||
)
|
}
|
||||||
.flatMap { files =>
|
.flatMap { files =>
|
||||||
Traverse[List].traverse(files)(toFileSystemEntry).map(_.flatten)
|
Traverse[List].traverse(files)(toFileSystemEntry).map(_.flatten)
|
||||||
}
|
}
|
||||||
@ -46,29 +51,37 @@ class FileSystemService[F[+_, +_]: Applicative: CovariantFlatMap: ErrorChannel](
|
|||||||
override def createDirectory(path: File): F[FileSystemServiceFailure, Unit] =
|
override def createDirectory(path: File): F[FileSystemServiceFailure, Unit] =
|
||||||
fileSystem
|
fileSystem
|
||||||
.createDir(path)
|
.createDir(path)
|
||||||
.mapError(_ =>
|
.mapError { error =>
|
||||||
|
logger.warn("Failed to create directory", error)
|
||||||
FileSystemServiceFailure.FileSystem("Failed to create directory")
|
FileSystemServiceFailure.FileSystem("Failed to create directory")
|
||||||
)
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** @inheritdoc */
|
||||||
override def delete(path: File): F[FileSystemServiceFailure, Unit] =
|
override def delete(path: File): F[FileSystemServiceFailure, Unit] =
|
||||||
fileSystem
|
fileSystem
|
||||||
.remove(path)
|
.remove(path)
|
||||||
.mapError(_ =>
|
.mapError { error =>
|
||||||
|
logger.warn("Failed to delete path", error)
|
||||||
FileSystemServiceFailure.FileSystem("Failed to delete path")
|
FileSystemServiceFailure.FileSystem("Failed to delete path")
|
||||||
)
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** @inheritdoc */
|
||||||
override def move(from: File, to: File): F[FileSystemServiceFailure, Unit] =
|
override def move(from: File, to: File): F[FileSystemServiceFailure, Unit] =
|
||||||
fileSystem
|
fileSystem
|
||||||
.move(from, to)
|
.move(from, to)
|
||||||
.mapError(_ => FileSystemServiceFailure.FileSystem("Failed to move path"))
|
.mapError { error =>
|
||||||
|
logger.warn("Failed to list directories", error)
|
||||||
|
FileSystemServiceFailure.FileSystem("Failed to move path")
|
||||||
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** @inheritdoc */
|
||||||
override def copy(from: File, to: File): F[FileSystemServiceFailure, Unit] =
|
override def copy(from: File, to: File): F[FileSystemServiceFailure, Unit] =
|
||||||
fileSystem
|
fileSystem
|
||||||
.copy(from, to)
|
.copy(from, to)
|
||||||
.mapError(_ => FileSystemServiceFailure.FileSystem("Failed to copy path"))
|
.mapError { error =>
|
||||||
|
logger.warn("Failed to copy path", error)
|
||||||
|
FileSystemServiceFailure.FileSystem("Failed to copy path")
|
||||||
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** @inheritdoc */
|
||||||
override def write(
|
override def write(
|
||||||
@ -77,9 +90,10 @@ class FileSystemService[F[+_, +_]: Applicative: CovariantFlatMap: ErrorChannel](
|
|||||||
): F[FileSystemServiceFailure, Unit] =
|
): F[FileSystemServiceFailure, Unit] =
|
||||||
fileSystem
|
fileSystem
|
||||||
.writeFile(path, contents)
|
.writeFile(path, contents)
|
||||||
.mapError(_ =>
|
.mapError { error =>
|
||||||
|
logger.warn("Failed to write path", error)
|
||||||
FileSystemServiceFailure.FileSystem("Failed to write path")
|
FileSystemServiceFailure.FileSystem("Failed to write path")
|
||||||
)
|
}
|
||||||
|
|
||||||
private def toFileSystemEntry(
|
private def toFileSystemEntry(
|
||||||
path: File
|
path: File
|
||||||
|
Loading…
Reference in New Issue
Block a user