Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 18, 2025

Thanks for asking me to work on this. I will get started on it and keep this PR's description up to date as I form a plan and make progress.

Original prompt

The CI job failed with a Swift compile error in Sources/prosign/views/CertificateView.swift when building the prosign target. Error: "value of optional type 'Date?' must be unwrapped to a value of type 'Date'" at the call expiryDisplay(for: expiry). See file at ref 900a7a5: Sources/prosign/views/CertificateView.swift.

Root cause:

  • The code stores certExpiries as [String: Date?] (an optional Date value for each key). In the certificateContent(for:) view it does if let expiry = certExpiries[cert.folderName] { expiryDisplay(for: expiry) }expiry here is Date? and must be unwrapped before passing to expiryDisplay(for:), which expects a non-optional Date.
  • There is also a force-unwrap (expiry!) in certificateBackground(for:) which is fragile and should be updated to safely unwrap the nested optional.

Requested change:

  • Update Sources/prosign/views/CertificateView.swift to safely unwrap the nested optional values before passing to expiryDisplay(for:) and before using expiry in certificateBackground(for:).
  • Keep behavior unchanged: show "No expiry date" when expiry is absent (nil), otherwise show expiryDisplay and background colors based on days until expiry.

Code changes to apply (replace the two relevant blocks):

  1. In certificateContent(for:), replace:

    if let expiry = certExpiries[cert.folderName] {
    expiryDisplay(for: expiry)
    } else {
    Text("No expiry date")
    .font(.caption)
    .fontWeight(.medium)
    .foregroundColor(.secondary)
    }

With:

if let expiryOptional = certExpiries[cert.folderName], let expiry = expiryOptional {
    expiryDisplay(for: expiry)
} else {
    Text("No expiry date")
        .font(.caption)
        .fontWeight(.medium)
        .foregroundColor(.secondary)
}
  1. In certificateBackground(for:), replace the guard and subsequent usage of expiry! with safe unwrapping. Replace:

    guard let expiry = certExpiries[cert.folderName], expiry != nil else {
    return Color.clear
    }
    let now = Date()
    let components = Calendar.current.dateComponents([.day], from: now, to: expiry!)

With:

guard let expiryOptional = certExpiries[cert.folderName], let expiry = expiryOptional else {
    return Color.clear
}
let now = Date()
let components = Calendar.current.dateComponents([.day], from: now, to: expiry)

Notes:

  • Use the repository ref 900a7a5 when referring to the file in the problem statement.
  • This is a small, self-contained fix to resolve the compile error and should not change UI behavior other than avoiding crashes or compile-time errors.

Please create a branch and open a pull request with these changes, using a concise PR title and description referencing the failing Actions run (https://github.com/ProStore-iOS/ProSign/actions/runs/18608043398/job/53061220254). Do not include unrelated changes.

This pull request was created as a result of the following prompt from Copilot chat.

The CI job failed with a Swift compile error in Sources/prosign/views/CertificateView.swift when building the prosign target. Error: "value of optional type 'Date?' must be unwrapped to a value of type 'Date'" at the call expiryDisplay(for: expiry). See file at ref 900a7a5: Sources/prosign/views/CertificateView.swift.

Root cause:

  • The code stores certExpiries as [String: Date?] (an optional Date value for each key). In the certificateContent(for:) view it does if let expiry = certExpiries[cert.folderName] { expiryDisplay(for: expiry) }expiry here is Date? and must be unwrapped before passing to expiryDisplay(for:), which expects a non-optional Date.
  • There is also a force-unwrap (expiry!) in certificateBackground(for:) which is fragile and should be updated to safely unwrap the nested optional.

Requested change:

  • Update Sources/prosign/views/CertificateView.swift to safely unwrap the nested optional values before passing to expiryDisplay(for:) and before using expiry in certificateBackground(for:).
  • Keep behavior unchanged: show "No expiry date" when expiry is absent (nil), otherwise show expiryDisplay and background colors based on days until expiry.

Code changes to apply (replace the two relevant blocks):

  1. In certificateContent(for:), replace:

    if let expiry = certExpiries[cert.folderName] {
    expiryDisplay(for: expiry)
    } else {
    Text("No expiry date")
    .font(.caption)
    .fontWeight(.medium)
    .foregroundColor(.secondary)
    }

With:

if let expiryOptional = certExpiries[cert.folderName], let expiry = expiryOptional {
    expiryDisplay(for: expiry)
} else {
    Text("No expiry date")
        .font(.caption)
        .fontWeight(.medium)
        .foregroundColor(.secondary)
}
  1. In certificateBackground(for:), replace the guard and subsequent usage of expiry! with safe unwrapping. Replace:

    guard let expiry = certExpiries[cert.folderName], expiry != nil else {
    return Color.clear
    }
    let now = Date()
    let components = Calendar.current.dateComponents([.day], from: now, to: expiry!)

With:

guard let expiryOptional = certExpiries[cert.folderName], let expiry = expiryOptional else {
    return Color.clear
}
let now = Date()
let components = Calendar.current.dateComponents([.day], from: now, to: expiry)

Notes:

  • Use the repository ref 900a7a5 when referring to the file in the problem statement.
  • This is a small, self-contained fix to resolve the compile error and should not change UI behavior other than avoiding crashes or compile-time errors.

Please create a branch and open a pull request with these changes, using a concise PR title and description referencing the failing Actions run (https://github.com/ProStore-iOS/ProSign/actions/runs/18608043398/job/53061220254). Do not include unrelated changes.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@NovaDev404 NovaDev404 marked this pull request as ready for review October 18, 2025 00:37
@NovaDev404 NovaDev404 merged commit e576c8d into main Oct 18, 2025
1 check failed
Copilot AI requested a review from NovaDev404 October 18, 2025 00:38
@NovaDev404 NovaDev404 deleted the copilot/fix-safe-unwrap-cert-expiry branch October 18, 2025 00:43
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.

2 participants