fix(secret-sync): handle Railway services with no deployments during sync#6873
fix(secret-sync): handle Railway services with no deployments during sync#6873devin-ai-integration[bot] wants to merge 1 commit into
Conversation
…sync Safely access the first deployment edge with optional chaining and skip the redeploy step when no deployments exist (e.g. cron services) instead of crashing with a TypeError. Co-Authored-By: ashwin <ashwin@infisical.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
| Filename | Overview |
|---|---|
| backend/src/services/secret-sync/railway/railway-sync-fns.ts | Added optional chaining on edges[0]?.node.id and changed the missing-deployment path from a thrown error to a graceful return, allowing services without deployments (e.g. cron jobs) to sync secrets successfully. |
Reviews (1): Last reviewed commit: "fix(secret-sync): handle Railway service..." | Re-trigger Greptile
| const latestDeploymentId = latestDeployment?.deployments.edges[0]?.node.id; | ||
|
|
||
| if (!latestDeploymentId) | ||
| throw new SecretSyncError({ | ||
| message: "Failed to get latest deployment from Railway" | ||
| }); | ||
| // Some Railway services (e.g. cron jobs) may not have deployments to redeploy | ||
| if (!latestDeploymentId) return; |
There was a problem hiding this comment.
Silent return also swallows unexpected API response shapes
The return on line 100 now fires for any falsy latestDeploymentId, not only when no deployments exist. If getDeployments returns a result where deployments is present but edges[0] has a falsy/empty id (e.g. an unexpected API shape change), the sync will report success while silently skipping the redeploy. The original guard at least surfaced that case as an observable failure. Consider logging a warning before returning so operators can distinguish "service has no deployments (expected)" from "service has deployments but the id was unexpectedly empty (unexpected)".
Context
Railway secret sync crashes with
"Failed to sync secrets to Railway"when the target service has no deployments (e.g. cron services).Root cause: In
syncSecrets, after upserting variables, the code fetches the latest deployment and accessesedges[0].node.idwithout checking ifedgesis empty. When a service (such as a Railway cron job) has no deployments,edges[0]isundefinedand.node.idthrows aTypeError, which gets caught by the generic handler and surfaced as a failed sync — even though the variables were written successfully.Fix:
edges[0]?.node.idSteps to verify the change
Type
Checklist
type(scope): short description(scope is optional, e.g.,fix: prevent crash on syncorfix(api): handle null response).Link to Devin session: https://app.devin.ai/sessions/47389380e59b4e2baa484bd70ebebd7a
Requested by: @ashwin-infisical