Skip to content

Commit e91272a

Browse files
marc0oloclaude
andcommitted
fix(rust/face-recognition): guard post_upgrade model reload with metadata check
storage::bytes() calls unwrap() and panics on missing files; check both model files exist before calling setup() to avoid trapping the canister on upgrade when models haven't been uploaded yet. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent ef7e9cf commit e91272a

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

  • rust/face-recognition/backend/src

rust/face-recognition/backend/src/lib.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,15 @@ fn post_upgrade() {
148148
let wasi_memory = MEMORY_MANAGER.with(|m| m.borrow().get(WASI_MEMORY_ID));
149149
ic_wasi_polyfill::init_with_memory(&[0u8; 32], &[], wasi_memory);
150150
// Reload models from stable memory if they were uploaded before this upgrade.
151-
// Silently ignored if the files don't exist yet (first deployment).
152-
let _ = setup(
153-
storage::bytes(FACE_DETECTION_FILE),
154-
storage::bytes(FACE_RECOGNITION_FILE),
155-
);
151+
// Guard with metadata check first — storage::bytes() panics on missing files.
152+
if std::fs::metadata(FACE_DETECTION_FILE).is_ok()
153+
&& std::fs::metadata(FACE_RECOGNITION_FILE).is_ok()
154+
{
155+
let _ = setup(
156+
storage::bytes(FACE_DETECTION_FILE),
157+
storage::bytes(FACE_RECOGNITION_FILE),
158+
);
159+
}
156160
}
157161

158162
ic_cdk::export_candid!();

0 commit comments

Comments
 (0)