{"record":{"id":"1338dde03b01d02a","repo":"semaphoreui/semaphore","slug":"invalid-environment-secret-type","errorCode":null,"errorMessage":"invalid environment secret type","messagePattern":"invalid environment secret type","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"db/Environment.go","lineNumber":78,"sourceCode":"\t// Sync fields are transfer-only; persisted in project__secret_sync.\n\tSyncEnabled      bool             `db:\"-\" json:\"sync_enabled\"`\n\tSyncInterval     int              `db:\"-\" json:\"sync_interval\"`\n\tLastSyncedAt     *time.Time       `db:\"-\" json:\"last_synced_at,omitempty\"`\n\tLastSyncFailedAt *time.Time       `db:\"-\" json:\"last_sync_failed_at,omitempty\"`\n\tSyncPaths        []SecretSyncPath `db:\"-\" json:\"sync_paths\"`\n}\n\nfunc (s *EnvironmentSecret) Validate() error {\n\n\tif s.Type == EnvironmentSecretVar || s.Type == EnvironmentSecretEnv {\n\t\treturn nil\n\t}\n\n\tif s.Secret == \"\" {\n\t\treturn errors.New(\"missing secret\")\n\t}\n\n\treturn errors.New(\"invalid environment secret type\")\n}\n\nfunc validateJSON(s string, mustValuesBeScalar bool) error {\n\tif s == \"\" {\n\t\treturn nil\n\t}\n\n\tvar data map[string]any\n\terr := json.Unmarshal([]byte(s), &data)\n\tif err != nil {\n\t\treturn errors.New(\"must be valid JSON\")\n\t}\n\n\tfor k, v := range data {\n\t\tif k == \"\" {\n\t\t\treturn errors.New(\"key can not be empty\")\n\t\t}\n","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/semaphoreui/semaphore/blob/1774ccb71a0a8b82eb74ea24c23ac9ab713de2fa/db/Environment.go#L60-L96","documentation":"Environment.Validate returns this error when an environment secret entry has a Type value outside the known set (EnvironmentSecretVar, EnvironmentSecretEnv, and the password-type checked earlier). The type field of each environment variable entry must be one of the recognized enum values; anything else is rejected as invalid.","triggerScenarios":"POST/PUT /api/environments with an env-vars JSON payload where an entry's \"type\" is misspelled, an arbitrary number/string, or from an older/removed enum value, so it matches none of the supported types in the Validate switch.","commonSituations":"Hand-written environment JSON with a typo in the type field; automation written against an older Semaphore API whose enum values changed; generated payloads emitting numeric enum values that no longer map to valid constants.","solutions":["Use one of the supported type values in the environment entry (the var/env types for plain values, the password type with a non-empty secret)","Compare your payload's type values against the EnvironmentSecret* constants in db/Environment.go for the version you run","Validate the environment JSON with the same switch logic client-side before calling the API"],"exampleFix":"// before\n{\"DEBUG\": {\"type\": \"string\", \"value\": \"1\"}}\n// after\n{\"DEBUG\": {\"type\": \"var\", \"value\": \"1\"}}","handlingStrategy":"validation","validationCode":"allowed := map[string]bool{\"var\": true, \"env\": true, \"password\": true}\nif !allowed[entry.Type] {\n\treturn fmt.Errorf(\"unsupported environment secret type %q\", entry.Type)\n}","typeGuard":"func isKnownSecretType(t db.EnvironmentSecretType) bool {\n\tswitch t {\n\tcase db.EnvironmentSecretVar, db.EnvironmentSecretEnv, db.EnvironmentSecretPassword:\n\t\treturn true\n\t}\n\treturn false\n}","tryCatchPattern":"if err := env.Validate(); err != nil {\n\tif strings.Contains(err.Error(), \"invalid environment secret type\") {\n\t\treturn fmt.Errorf(\"environment rejected: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Copy type values from the current Semaphore API docs/constants, not older integrations","Use the Go constants (db.EnvironmentSecret*) instead of raw literals in code","Add client-side enum validation before generating environment payloads"],"tags":["go","validation","environment","enum"],"backgroundTag":"invalid-enum-value","analyzedSha":"1774ccb71a0a8b82eb74ea24c23ac9ab713de2fa","analyzedAt":"2026-09-07T11:00:33.293Z","contentChangedAt":"2026-09-07T11:00:33.293Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}