package console import ( "fmt" "strings" ) // The nearest-region feature's API and operator messages (spec ยง19), as // approved in the nearest-region copy record. Change none of them without a // new copy review. // // Where a message takes a list ("Choose from: %s."), the caller passes the // region codes and the message joins them with ", ". An empty list never // renders as a list: the b variant drops the list sentence (codex plan-R4 2, // a list names only what the door would accept, so it can be empty). // reasonText turns a refusal reason (absent, not-hosting, no-secrets-key, // not-eligible) into the words C16 puts in its brackets (R-absent, // R-not-hosting, R-no-secrets-key, R-not-eligible). An unknown reason passes // through unchanged. func reasonText(reason string) string { switch reason { case "absent": return "no box runs there now" case "not-hosting": return "boxes there can't start instances" case "no-secrets-key": return "boxes there can't open this deployment's secrets" case "not-eligible": return "boxes there don't take ordinary instances" } return reason } // msgAppRegionUnavailable is C16, or C16b when can is empty. The verbs are // the app's region code, the reason text and the joined list. func msgAppRegionUnavailable(code, reason string, can []string) string { if len(can) == 0 { return fmt.Sprintf("this app's region %s can't take new instances right now (%s), and no other region this app may use can either. Try again later.", code, reasonText(reason)) } return fmt.Sprintf("this app's region %s can't take new instances right now (%s). Pass a region to place this instance elsewhere. Regions that can: %s.", code, reasonText(reason), strings.Join(can, ", ")) } // msgAppRegionNotAllowed is C17, or C17b when allowed is empty. func msgAppRegionNotAllowed(code string, allowed []string) string { if len(allowed) == 0 { return fmt.Sprintf("this app's region %s is not one its instances may use, and no region they may use can take new instances right now. Try again later.", code) } return fmt.Sprintf("this app's region %s is not one its instances may use. Allowed: %s. Pass a region to choose one.", code, strings.Join(allowed, ", ")) } // msgRegionUnknown is C18, or C18b when choices is empty. func msgRegionUnknown(code string, choices []string) string { if len(choices) == 0 { return fmt.Sprintf("region %s is not one this platform runs in. Run the command without --region.", code) } return fmt.Sprintf("region %s is not one this platform runs in. Choose from: %s.", code, strings.Join(choices, ", ")) } // msgRegionNotArmed is C19, or C19b when choices is empty. func msgRegionNotArmed(code string, choices []string) string { if len(choices) == 0 { return fmt.Sprintf("region %s can't take new apps right now. Run the command without --region.", code) } return fmt.Sprintf("region %s can't take new apps right now. Choose from: %s.", code, strings.Join(choices, ", ")) } // msgAppRegionUnreadable is C20. const msgAppRegionUnreadable = "could not read this app's region. Try again." // msgReplicaOverlap is C26. The region code fills both verbs. func msgReplicaOverlap(code string) string { return fmt.Sprintf("this app's region %s is also one of this instance's replica placements. Pass a region for the instance, or drop %s from replicas.", code, code) } // msgPolicyUnreadable is C27. const msgPolicyUnreadable = "could not read this app's instance policy, so there is no region suggestion. Try again." // msgAppRegionUnconfirmed is C28. func msgAppRegionUnconfirmed(code string) string { return fmt.Sprintf("could not confirm that this app's region %s can take new instances. Try again, or pass a region.", code) } // msgPlacementDiscrepancy is C29, an operator log line. The app name fills // the second and third verbs. func msgPlacementDiscrepancy(host, app, code string) string { return fmt.Sprintf("possible placement discrepancy: %s of %s has no region, but %s's region is %s. It may be a deliberate home override; review it.", host, app, app, code) } // msgNoSecretsKey is C31 (R9). func msgNoSecretsKey(code string) string { return fmt.Sprintf("region %s can't run instances right now: its boxes don't hold this deployment's secrets key, so an instance there would start without its config or secrets. Choose another region.", code) }