Validate workspace color during cmux.json decode (#2112)

Reject invalid color values at parse time with a clear error message
instead of silently ignoring them. Colors are normalized to #RRGGBB
via WorkspaceTabColorSettings.normalizedHex during decode.

Co-authored-by: Lawrence Chen <lawrencecchen@users.noreply.github.com>
This commit is contained in:
Lawrence Chen 2026-03-24 22:58:27 -07:00 committed by GitHub
parent 321f8c14c8
commit 23253e6ddf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -95,6 +95,33 @@ struct CmuxWorkspaceDefinition: Codable, Sendable {
var cwd: String?
var color: String?
var layout: CmuxLayoutNode?
init(name: String? = nil, cwd: String? = nil, color: String? = nil, layout: CmuxLayoutNode? = nil) {
self.name = name
self.cwd = cwd
self.color = color
self.layout = layout
}
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
name = try container.decodeIfPresent(String.self, forKey: .name)
cwd = try container.decodeIfPresent(String.self, forKey: .cwd)
layout = try container.decodeIfPresent(CmuxLayoutNode.self, forKey: .layout)
if let rawColor = try container.decodeIfPresent(String.self, forKey: .color) {
guard let normalized = WorkspaceTabColorSettings.normalizedHex(rawColor) else {
throw DecodingError.dataCorruptedError(
forKey: .color,
in: container,
debugDescription: "Invalid color \"\(rawColor)\". Expected 6-digit hex format: #RRGGBB"
)
}
color = normalized
} else {
color = nil
}
}
}
indirect enum CmuxLayoutNode: Codable, Sendable {