From 3b1f2cc6d287f4ef95d16d820eb61f3d3314415f Mon Sep 17 00:00:00 2001 From: nobe4 Date: Mon, 10 Nov 2025 12:29:43 +0100 Subject: [PATCH 1/3] feat: add custom error for when a file can't be parsed into the cache --- lib/entitlements/data/groups/cached.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/entitlements/data/groups/cached.rb b/lib/entitlements/data/groups/cached.rb index 66663f8..555a510 100644 --- a/lib/entitlements/data/groups/cached.rb +++ b/lib/entitlements/data/groups/cached.rb @@ -51,6 +51,8 @@ def self.load_caches(dir) Entitlements.cache[:predictive_state][:by_ou][ou] ||= {} Entitlements.cache[:predictive_state][:by_ou][ou][identifier] = member_set Entitlements.cache[:predictive_state][:by_dn][dn] = { members: member_set, metadata: metadata } + rescue => e + raise "Failed to load predictive state cache file #{filename}: #{e.message}" end Entitlements.logger.debug "Loaded #{Entitlements.cache[:predictive_state][:by_ou].keys.size} OU(s) from cache" From 038c6b4ce8529c41dea82cc8bddad8d9ac8ae398 Mon Sep 17 00:00:00 2001 From: nobe4 Date: Mon, 10 Nov 2025 12:32:36 +0100 Subject: [PATCH 2/3] feat: bump version --- lib/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/version.rb b/lib/version.rb index 2d8fb73..629fcc9 100644 --- a/lib/version.rb +++ b/lib/version.rb @@ -2,6 +2,6 @@ module Entitlements module Version - VERSION = "1.1.0" + VERSION = "1.1.1" end end From dcbb6b7b0441ab3ae0d761c543e295c01be63b8f Mon Sep 17 00:00:00 2001 From: nobe4 Date: Mon, 10 Nov 2025 12:40:46 +0100 Subject: [PATCH 3/3] fix: add spec --- Gemfile.lock | 2 +- spec/unit/entitlements/data/groups/cached_spec.rb | 12 ++++++++++++ .../cn=admin,ou=org,ou=fakegithub,dc=github,dc=fake | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 spec/unit/fixtures/predictive-state/failing-cache/cn=admin,ou=org,ou=fakegithub,dc=github,dc=fake diff --git a/Gemfile.lock b/Gemfile.lock index e52d4cb..cff72c0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - entitlements-app (1.2.0) + entitlements-app (1.2.1) concurrent-ruby (~> 1.3, >= 1.3.1) faraday (~> 2.0) logger (~> 1.6) diff --git a/spec/unit/entitlements/data/groups/cached_spec.rb b/spec/unit/entitlements/data/groups/cached_spec.rb index a7a41d7..25ce6ea 100644 --- a/spec/unit/entitlements/data/groups/cached_spec.rb +++ b/spec/unit/entitlements/data/groups/cached_spec.rb @@ -17,6 +17,18 @@ end end + context "with a file that fails to parse" do + let(:dir) { fixture("predictive-state/failing-cache") } + + it "raises with a custom message" do + expect(logger).to receive(:debug).with("Loading predictive update caches from #{dir}") + + expect do + described_class.load_caches(dir) + end.to raise_error(RuntimeError, /Failed to load predictive state cache file/) + end + end + context "with valid predictive state directory" do let(:dir) { fixture("predictive-state/cache1") } diff --git a/spec/unit/fixtures/predictive-state/failing-cache/cn=admin,ou=org,ou=fakegithub,dc=github,dc=fake b/spec/unit/fixtures/predictive-state/failing-cache/cn=admin,ou=org,ou=fakegithub,dc=github,dc=fake new file mode 100644 index 0000000..6a0de29 --- /dev/null +++ b/spec/unit/fixtures/predictive-state/failing-cache/cn=admin,ou=org,ou=fakegithub,dc=github,dc=fake @@ -0,0 +1 @@ +metadata_is_missing_a_value