Skip to content

persistence: replace try! with guard-let in defaultMemory#1851

Open
ArasanDev wants to merge 1 commit into
apple:mainfrom
ArasanDev:fix/machine-config-force-try
Open

persistence: replace try! with guard-let in defaultMemory#1851
ArasanDev wants to merge 1 commit into
apple:mainfrom
ArasanDev:fix/machine-config-force-try

Conversation

@ArasanDev

Copy link
Copy Markdown

Type of Change

  • Bug fix

Motivation and Context

In MachineConfig.defaultMemory, the MemorySize initializer is called with try! inside a computed property getter:

return try! MemorySize("\(gb)gb")

This is a NeverForceTry violation — the exemption for static let initializers does not apply to computed property getters. The input is a runtime-derived string ("\(gb)gb"), so a defensive fallback is appropriate.

Replaced with guard let + fatalError:

guard let size = try? MemorySize("\(gb)gb") else {
    fatalError("invalid default memory size: \(gb)gb")
}
return size

Testing

  • Tested locally
  • make test passes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant