JamieMason/syncpack

View on GitHub
src/io/read-yaml-file-sync.ts

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
import { Data, Effect } from 'effect';
import type { Io } from './index.js';

class ReadYamlFileError extends Data.TaggedClass('ReadYamlFileError')<{
  readonly filePath: string;
  readonly error: string;
}> {}

export function readYamlFileSync<T = unknown>(
  io: Io,
  filePath: string,
): Effect.Effect<T, ReadYamlFileError> {
  return Effect.try({
    try: () => io.readYamlFile.sync(filePath),
    catch: (err) => new ReadYamlFileError({ filePath, error: String(err) }),
  });
}