Skip to content

Conversation

@HarshMN2345
Copy link
Member

@HarshMN2345 HarshMN2345 commented Nov 21, 2025

What does this PR do?

(Provide a description of what this PR does.)

Test Plan

image image

Related PRs and Issues

(If this PR is related to any other PR or resolves any issue or related to any issue link all related PR and issues here.)

Have you read the Contributing Guidelines on issues?

(Write your answer here.)

Summary by CodeRabbit

  • Bug Fixes
    • Improved resilience across project pages by adding error handling for deployment retrieval, gracefully handling cases where deployments are unavailable or inaccessible.
  • New/Updated Behavior
    • Site pages now explicitly include the active deployment (when available); if retrieval fails the UI will treat it as unavailable rather than erroring.

✏️ Tip: You can customize this high-level summary in your review settings.

✏️ Tip: You can customize this high-level summary in your review settings.

@appwrite
Copy link

appwrite bot commented Nov 21, 2025

Console (appwrite/console)

Project ID: 688b7bf400350cbd60e9

Sites (1)
Site Status Logs Preview QR
 console-stage
688b7cf6003b1842c9dc
Ready Ready View Logs Preview URL QR Code

Tip

Sites auto-generate unique domains with the pattern https://randomstring.appwrite.network

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 21, 2025

Walkthrough

Refactors deployment retrieval in three route files by adding a Models type import, introducing a local activeDeployment: Models.Deployment | null = null, and replacing inline conditional fetches with a guarded try/catch fetch that leaves activeDeployment null on error. Each load now returns the precomputed activeDeployment instead of performing inline retrieval; additionally, sites/site-[site]/+page.ts adds a deployment property to its returned payload.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Files to inspect closely:
    • src/routes/(console)/project-[region]-[project]/functions/function-[function]/+page.ts — verify try/catch behavior and null fallback.
    • src/routes/(console)/project-[region]-[project]/sites/site-[site]/+page.ts — public return payload now includes deployment; check callers for compatibility.
    • src/routes/(console)/project-[region]-[project]/sites/site-[site]/deployments/+page.ts — ensure consistent error handling and no change in pagination/query behavior.
  • Confirm Models import usage and type correctness across the three files.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: handle missing deploymentId gracefully' accurately describes the main change—adding defensive error handling for missing deployment IDs across three files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-SER-635-handle-missing-deployment-id

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
src/routes/(console)/project-[region]-[project]/functions/function-[function]/+page.ts (1)

18-31: Graceful handling of missing function deployment looks good; consider small cleanups.

The new activeDeployment logic correctly guards on data.function.deploymentId and safely falls back to null on any retrieval error, which aligns with the PR’s goal of not breaking the page when the deployment is missing.

Two minor follow-ups you might consider:

  • Since the caught error is not used, some TS/lint configs will complain. If you intend to ignore all errors here, either drop the binding (catch { ... }) or rename to _error to satisfy lint rules.
  • You can avoid repeating sdk.forProject(params.region, params.project) and slightly simplify the code by caching the project SDK once and reusing it for both getDeployment and listDeployments:
-    const parsedQueries = queryParamToMap(query || '[]');
-    queries.set(parsedQueries);
-    let activeDeployment = null;
+    const parsedQueries = queryParamToMap(query || '[]');
+    queries.set(parsedQueries);
+    const projectSdk = sdk.forProject(params.region, params.project);
+    let activeDeployment = null;
@@
-            activeDeployment = await sdk
-                .forProject(params.region, params.project)
-                .functions.getDeployment({
+            activeDeployment = await projectSdk.functions.getDeployment({
                 functionId: params.function,
                 deploymentId: data.function.deploymentId
             });
-        } catch (error) {
+        } catch {
             // active deployment with the requested ID could not be found
             activeDeployment = null;
         }
@@
-        deploymentList: await sdk
-            .forProject(params.region, params.project)
-            .functions.listDeployments({
+        deploymentList: await projectSdk.functions.listDeployments({

These are non-blocking and mainly for cleanliness and minor reuse.

Also applies to: 39-42

src/routes/(console)/project-[region]-[project]/sites/site-[site]/+page.ts (1)

49-59: Deployment fetch is robust; tighten error handling and guard hasProdReadyDeployments.

The guarded deployment lookup behaves as intended: it only runs when both deploymentList.total and site.deploymentId exist, and failures are handled by falling back to null so the rest of the page data is still usable.

A couple of small improvements you might want to apply:

  • The caught error is unused; if you don’t plan to log or branch on it, you can simplify the block and avoid potential lint issues:
-        } catch (error) {
+        } catch {
             // active deployment with the requested ID could not be found
             deployment = null;
         }
  • hasProdReadyDeployments currently calls .length on the result of prodReadyDeployments?.deployments?.filter(...). If either prodReadyDeployments or .deployments is undefined, this expression will throw at runtime (this is pre-existing, but worth fixing while you’re here). You can safely default to an empty array:
-        hasProdReadyDeployments:
-            prodReadyDeployments?.deployments?.filter((d) => d?.$id !== deployment?.$id).length > 0
+        hasProdReadyDeployments:
+            (prodReadyDeployments?.deployments ?? [])
+                .filter((d) => d?.$id !== deployment?.$id).length > 0

This keeps the semantics the same while making the code more defensive.

Also applies to: 61-69

src/routes/(console)/project-[region]-[project]/sites/site-[site]/deployments/+page.ts (1)

40-50: Consistent activeDeployment handling; consider minor refactor and catch cleanup.

The activeDeployment computation mirrors the new pattern in other routes: it’s gated on both site.deploymentId and deploymentList.total and safely degrades to null on any error, which should handle missing/removed deployments without failing the page.

Two small tidy-ups to consider:

  • As in the other files, the caught error is unused. If intentional, you can remove the binding:
-        } catch (error) {
+        } catch {
             // active deployment with the requested ID could not be found
             activeDeployment = null;
         }
  • For consistency and to avoid repeating sdk.forProject(params.region, params.project) in multiple places in this file, you could cache it once near the top of load (similar to the diff suggested in the functions page) and call projectSdk.sites.getDeployment(...) / projectSdk.sites.listDeployments(...).

These are non-blocking and mainly improve readability and maintainability.

Also applies to: 52-58

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 81c53a4 and f1d40ae.

📒 Files selected for processing (3)
  • src/routes/(console)/project-[region]-[project]/functions/function-[function]/+page.ts (1 hunks)
  • src/routes/(console)/project-[region]-[project]/sites/site-[site]/+page.ts (1 hunks)
  • src/routes/(console)/project-[region]-[project]/sites/site-[site]/deployments/+page.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
src/routes/(console)/project-[region]-[project]/sites/site-[site]/deployments/+page.ts (1)
src/lib/stores/sdk.ts (1)
  • sdk (171-194)
src/routes/(console)/project-[region]-[project]/sites/site-[site]/+page.ts (2)
src/routes/(console)/project-[region]-[project]/functions/function-[function]/store.ts (1)
  • deploymentList (8-11)
src/lib/stores/sdk.ts (1)
  • sdk (171-194)
src/routes/(console)/project-[region]-[project]/functions/function-[function]/+page.ts (1)
src/lib/stores/sdk.ts (1)
  • sdk (171-194)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: e2e
  • GitHub Check: build


const parsedQueries = queryParamToMap(query || '[]');
queries.set(parsedQueries);
let activeDeployment = null;
Copy link
Member

Choose a reason for hiding this comment

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

lets add the variable type as well, just for visibility.

sdk.forProject(params.region, params.project).vcs.listInstallations()
]);

let activeDeployment = null;
Copy link
Member

Choose a reason for hiding this comment

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

same here.

.forProject(params.region, params.project)
.sites.getDeployment({ siteId: params.site, deploymentId: site.deploymentId })
: null;
let deployment = null;
Copy link
Member

Choose a reason for hiding this comment

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

same.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/routes/(console)/project-[region]-[project]/sites/site-[site]/deployments/+page.ts (1)

1-1: Guarded activeDeployment fetch matches PR goal; consider optional diagnostics

The precomputed activeDeployment: Models.Deployment | null with a try/catch cleanly handles missing or invalid site.deploymentId by falling back to null, while keeping the rest of the page data intact. If you later need to debug non‑404 failures, you might add lightweight logging or narrow the catch to known “not found” cases, but the current behavior is fine for graceful degradation.

Also applies to: 40-50, 57-57

src/routes/(console)/project-[region]-[project]/sites/site-[site]/+page.ts (1)

3-3: Site deployment retrieval now degrades gracefully on missing IDs

The explicit deployment: Models.Deployment | null plus guarded sites.getDeployment call correctly shields this route from stale or missing site.deploymentId while preserving existing uses of deployment (including hasProdReadyDeployments). As with the deployments page, you might optionally log inside the catch or specialize for “not found” errors if distinguishing backend issues ever becomes important.

Also applies to: 49-59

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f1d40ae and 667cc6c.

📒 Files selected for processing (3)
  • src/routes/(console)/project-[region]-[project]/functions/function-[function]/+page.ts (2 hunks)
  • src/routes/(console)/project-[region]-[project]/sites/site-[site]/+page.ts (2 hunks)
  • src/routes/(console)/project-[region]-[project]/sites/site-[site]/deployments/+page.ts (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: ItzNotABug
Repo: appwrite/console PR: 2316
File: src/routes/(console)/project-[region]-[project]/functions/create-function/deploy/+page.svelte:95-103
Timestamp: 2025-09-08T13:21:53.793Z
Learning: In Appwrite's one-click deployment flows, Git tag validation should be lenient with fallbacks (like '1.0.0') rather than strict validation that blocks deployments, since the source code retrieval from the repository is more important than having proper version tags for the deployment to succeed.
🧬 Code graph analysis (3)
src/routes/(console)/project-[region]-[project]/functions/function-[function]/+page.ts (1)
src/lib/stores/sdk.ts (1)
  • sdk (171-194)
src/routes/(console)/project-[region]-[project]/sites/site-[site]/+page.ts (2)
src/routes/(console)/project-[region]-[project]/functions/function-[function]/store.ts (1)
  • deploymentList (8-11)
src/lib/stores/sdk.ts (1)
  • sdk (171-194)
src/routes/(console)/project-[region]-[project]/sites/site-[site]/deployments/+page.ts (2)
src/routes/(console)/project-[region]-[project]/functions/function-[function]/store.ts (1)
  • deploymentList (8-11)
src/lib/stores/sdk.ts (1)
  • sdk (171-194)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: e2e
  • GitHub Check: build
🔇 Additional comments (1)
src/routes/(console)/project-[region]-[project]/functions/function-[function]/+page.ts (1)

1-1: Function activeDeployment handling is consistent and robust

Typing activeDeployment as Models.Deployment | null and guarding the functions.getDeployment call behind data.function.deploymentId with a try/catch gives the functions page the same graceful behavior as the site pages when a deployment is missing or deleted, without changing the returned data shape.

Also applies to: 18-31, 38-38

@ItzNotABug ItzNotABug merged commit 553587e into main Nov 21, 2025
4 checks passed
@ItzNotABug ItzNotABug deleted the fix-SER-635-handle-missing-deployment-id branch November 21, 2025 07:31
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.

3 participants