oaspec/codegen/writer

Types

Errors that can occur during file writing.

pub type WriteError {
  DirectoryCreateError(path: String, detail: String)
  FileWriteError(path: String, detail: String)
}

Constructors

  • DirectoryCreateError(path: String, detail: String)
  • FileWriteError(path: String, detail: String)

Values

pub fn error_to_string(error: WriteError) -> String

Convert a write error to a human-readable string.

pub fn expected_paths(
  files: List(@internal GeneratedFile),
  cfg: config.Config,
) -> List(String)

Every file path the generator would write for the given config — including SkipIfExists files. Used by --check to keep user-owned handlers.gleam off the orphan list while still excluding it from byte-comparison drift reports (resolve_paths drops SkipIfExists entries).

Same path-overlap dedup as resolve_paths (#548): shared files appear once when the two output directories coincide.

pub fn output_dirs(cfg: config.Config) -> List(String)

Return the output directories that would be written to for the given config.

pub fn resolve_paths(
  files: List(@internal GeneratedFile),
  cfg: config.Config,
) -> List(#(String, String))

Resolve generated files to their full output paths and content. Used by –check to compare against existing files without writing.

Issue #247: SkipIfExists files (e.g. user-owned handlers.gleam) are dropped from the result. --check is meant to flag drift in generator-owned files; user-edited files are expected to differ from the bootstrap stub and should not be reported as out-of-date.

Issue #548: when mode = Both and output_server resolves to the same directory as output_client, shared files appear once in the result, not twice — --check would otherwise compare the same file twice and double-count any drift.

pub fn write_all(
  files: List(@internal GeneratedFile),
  cfg: config.Config,
  on_write: fn(String) -> Nil,
) -> Result(List(String), WriteError)

Write pre-generated files to disk based on configuration.

Path overlap. When mode = Both and output_server resolves to the same directory as output_client (e.g. both set to "out", or to "out" and "out/", which differ as strings but name the same directory), shared files are written once, not twice. Each unique destination path triggers on_write exactly once and appears at most once in the returned list. Distinct server / client paths preserve the existing behaviour: shared files land in both directories.

Search Document