Skip to content

Fix deserialization error when Homebrew returns null installation timestamps#20

Merged
cosmincatalin merged 5 commits intomainfrom
copilot/fix-package-loading-error
Oct 21, 2025
Merged

Fix deserialization error when Homebrew returns null installation timestamps#20
cosmincatalin merged 5 commits intomainfrom
copilot/fix-package-loading-error

Conversation

Copy link
Contributor

Copilot AI commented Oct 20, 2025

Problem

The application was failing to load packages from Homebrew with the following error:

Error loading packages from Homebrew: invalid type: null, expected u64 at line 5159 column 22.
Make sure Homebrew is installed and accessible.

This resulted in only a "homebrew-error" placeholder being displayed instead of the user's installed packages:

Root Cause

The BrewInstalled struct defined the time field as a non-nullable u64, but Homebrew's JSON API can return null for installation timestamps in certain scenarios:

  • Packages installed before Homebrew implemented timestamp tracking
  • Certain installation methods that don't record timestamps
  • Manual installations or package migrations

When serde_json attempted to deserialize a JSON response with a null time field, it raised a deserialization error that prevented all packages from loading.

Solution

Changed the time field from u64 to Option<u64> to handle both valid timestamps and null values gracefully:

pub struct BrewInstalled {
    pub version: String,
    pub time: Option<u64>,  // Now accepts both timestamps and null
    pub installed_as_dependency: bool,
    pub installed_on_request: bool,
}

Packages with null timestamps are treated as having timestamp 0 (Unix epoch) for sorting and comparison purposes, ensuring consistent behaviour across the application.

Changes

  • src/entities/brew_info_response.rs: Changed time: u64time: Option<u64> and added test for null timestamp deserialization; merged with null homepage handling from main
  • src/entities/package_info.rs: Updated to handle Option<u64> when finding the latest installation; includes null homepage handling
  • src/repository.rs: Updated timestamp comparison logic to handle optional timestamps; includes null homepage handling
  • Cargo.toml: Bumped version from 0.1.3 to 0.1.4
  • Cargo.lock: Updated dependencies to latest compatible versions

Testing

  • Added new test test_deserialize_formula_with_null_time to verify null timestamps are handled correctly
  • Merged with main branch which included tests for null homepage handling
  • All 12 tests pass (8 original + 3 for null homepage + 1 for null time)
  • No clippy warnings
  • Code formatted with rustfmt
  • Release build succeeds

Impact

Before: Application crashed when encountering packages with null timestamps
After: All packages load successfully, including those with null timestamps and null homepages

This fix ensures brew-explorer works reliably for all Homebrew installations, regardless of whether packages have timestamp or homepage information available.

Fixes #17

Original prompt

This section details on the original issue you should resolve

<issue_title>Fails to load packages — invalid type: null, expected u64 error</issue_title>
<issue_description>After installing brew-explorer via Homebrew, the app opens, spends ~8s loading packages, and then but immediately displays an error instead of listing any packages:

Error loading packages from Homebrew: invalid type: null, expected u64 at line 5159 column 22.  
Make sure Homebrew is installed and accessible.
Image

Observed behavior:

  • The UI opens but lists only a placeholder entry named homebrew-error.
  • No installed packages are displayed.
  • Homebrew commands (brew list, brew info, etc.) function normally outside of brew-explorer.

Environment details:

  • System: macOS Sequoia 15.0 (Darwin 25.0.0, arm64 / Apple Silicon)
  • Homebrew version: 4.6.17
  • Binary location: /opt/homebrew/bin/brew-explorer</issue_description>

Comments on the Issue (you are @copilot in this section)

@cosmincatalin Hi @VildMedPap, I might need some help fixing this.

On my side, I should probably add a better error message.

On your side, can you do some debugging similar to what was done in #2 by @unnamedd?</comment_new>
<comment_new>@cosmincatalin
Brilliant, I'll fix it asap.</comment_new>

Fixes #17


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI self-assigned this Oct 20, 2025
Co-authored-by: cosmincatalin <525590+cosmincatalin@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix error loading packages in brew-explorer Fix deserialization error when Homebrew returns null installation timestamps Oct 20, 2025
Copilot AI requested a review from cosmincatalin October 20, 2025 18:47
Copy link
Owner

@cosmincatalin cosmincatalin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to also bump the version

@cosmincatalin
Copy link
Owner

cosmincatalin commented Oct 20, 2025

The version of the package needs to be bumped up at patch version.
cargo udpate needs to be run.
@copilot

@cosmincatalin cosmincatalin marked this pull request as ready for review October 21, 2025 07:09
Copy link
Owner

@cosmincatalin cosmincatalin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version of the app needs to be bumped with a patch increment.
After this, cargo update needs to be run.

@cosmincatalin cosmincatalin removed their assignment Oct 21, 2025
@cosmincatalin
Copy link
Owner

@copilot , fix the conflicts and do the work.

Co-authored-by: cosmincatalin <525590+cosmincatalin@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 21, 2025

@copilot , fix the conflicts and do the work.

Fixed merge conflicts and bumped version to 0.1.4 in commit 70f32cb. The branch now includes both the null time field fix and the null homepage fix from main. All 12 tests pass.

@copilot , fix the conflicts and do the work.

Fixed merge conflicts and bumped version to 0.1.4 in commit 1f94ca8. The branch now includes both the null time field fix and the null homepage fix from main. All 12 tests pass.

@cosmincatalin cosmincatalin merged commit abe8f48 into main Oct 21, 2025
0 of 2 checks passed
@cosmincatalin cosmincatalin deleted the copilot/fix-package-loading-error branch October 21, 2025 16:11
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.

Fails to load packages — invalid type: null, expected u64 error

2 participants