Skip to content

Extract shared YAML load/save helper #274

@bguidolim

Description

@bguidolim

Context

MCSConfig, PackRegistryFile, ProjectIndex, and Lockfile all implement the same YAML persistence boilerplate:

Load: guard empty → String(contentsOf:)YAMLDecoder().decode()
Save: mkdir → YAMLEncoder().encode()write(to:atomically:)

Each has small nuances (MCSConfig swallows errors, others throw), but the structural pattern is identical.

Proposed Change

Extract a generic helper, e.g.:

enum YAMLFile {
    static func load<T: Decodable>(_ type: T.Type, from path: URL) throws -> T?
    static func save<T: Encodable>(_ value: T, to path: URL) throws
}

Each caller can wrap this with its own error-handling policy (swallow vs throw).

Files to Modify

  • Sources/mcs/Core/MCSConfig.swift
  • Sources/mcs/ExternalPack/PackRegistryFile.swift
  • Sources/mcs/Core/ProjectIndex.swift
  • Sources/mcs/Core/Lockfile.swift

Metadata

Metadata

Assignees

No one assigned

    Labels

    DRYCode duplication / DRY violationtech-debtTechnical debt and code quality improvements

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions