Skip to content

Commit afdb26d

Browse files
hobostayclaude
andcommitted
fix: correct error message for full label length validation
Fix incorrect error message in NetworkConfiguration label validation. The error previously stated "key length is greater than" when actually checking the full label length (key=value combination). Changes: - Update error message to say "full label length (key=value)" instead of "key length" - Add test case to verify the error message is correct This makes the error message more accurate and helpful for users debugging label validation issues. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 474906d commit afdb26d

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

Sources/ContainerResource/Network/NetworkConfiguration.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public struct NetworkConfiguration: Codable, Sendable, Identifiable {
120120

121121
let fullLabel = "\(key)=\(value)"
122122
guard fullLabel.count <= labelLengthMax else {
123-
throw ContainerizationError(.invalidArgument, message: "invalid label, key length is greater than \(labelLengthMax): \(fullLabel)")
123+
throw ContainerizationError(.invalidArgument, message: "invalid label, full label length (key=value) is greater than \(labelLengthMax): \(fullLabel)")
124124
}
125125
}
126126
}

Tests/ContainerResourceTests/NetworkConfigurationTest.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,22 @@ struct NetworkConfigurationTest {
102102
}
103103
}
104104

105+
@Test func testFullLabelLengthErrorMessage() throws {
106+
// Test that the error message correctly mentions "full label length" instead of "key length"
107+
let id = "foo"
108+
let ipv4Subnet = try CIDRv4("192.168.64.1/24")
109+
// Create a label where the full label (key=value) exceeds 4096 chars
110+
let labels = ["test-key": String(repeating: "x", count: 4097 - "test-key=".count)]
111+
112+
#expect {
113+
_ = try NetworkConfiguration(id: id, mode: .nat, ipv4Subnet: ipv4Subnet, labels: labels)
114+
} throws: { error in
115+
guard let err = error as? ContainerizationError else { return false }
116+
#expect(err.code == .invalidArgument)
117+
// Verify the error message mentions "full label length" not just "key length"
118+
#expect(err.message.contains("full label length"))
119+
return true
120+
}
121+
}
122+
105123
}

0 commit comments

Comments
 (0)