{"record":{"id":"3f95a2ece145f700","repo":"coleam00/Archon","slug":"gitlabadapter-requires-a-non-empty-token","errorCode":null,"errorMessage":"GitLabAdapter requires a non-empty token","messagePattern":"GitLabAdapter requires a non-empty token","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/adapters/src/community/forge/gitlab/adapter.ts","lineNumber":71,"sourceCode":"type ConversationLocker = Pick<ConversationLockManager, 'acquireLock'>;\n\nexport class GitLabAdapter implements IPlatformAdapter {\n  private readonly gitlabUrl: string;\n  private readonly token: string;\n  private readonly webhookSecret: string;\n  private readonly allowedUsers: string[];\n  private readonly botMention: string;\n  private readonly lockManager: ConversationLocker;\n\n  constructor(\n    token: string,\n    webhookSecret: string,\n    lockManager: ConversationLocker,\n    gitlabUrl?: string,\n    botMention?: string\n  ) {\n    if (!token) {\n      throw new Error('GitLabAdapter requires a non-empty token');\n    }\n    if (!webhookSecret) {\n      throw new Error('GitLabAdapter requires a non-empty webhookSecret');\n    }\n\n    this.gitlabUrl = (gitlabUrl ?? 'https://gitlab.com').replace(/\\/+$/, '');\n    this.token = token;\n    this.webhookSecret = webhookSecret;\n    this.lockManager = lockManager;\n    this.botMention = botMention ?? 'Archon';\n\n    this.allowedUsers = parseAllowedUsers(process.env.GITLAB_ALLOWED_USERS);\n    if (this.allowedUsers.length > 0) {\n      getLog().info({ userCount: this.allowedUsers.length }, 'gitlab.whitelist_enabled');\n    } else {\n      getLog().info('gitlab.whitelist_disabled');\n    }\n","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/coleam00/Archon/blob/0773b9745896ef0612e709c80845a0f7db315b19/packages/adapters/src/community/forge/gitlab/adapter.ts#L53-L89","documentation":"The GitLabAdapter constructor validates its required credentials at instantiation time: an empty (or falsy) token cannot authenticate any GitLab API call, so the adapter fails fast instead of producing confusing 401s later. It performs the same check for webhookSecret immediately after.","triggerScenarios":"new GitLabAdapter(...) called with token === '' , undefined, or null — typically from an unset GITLAB_TOKEN environment variable or an empty string in the config file.","commonSituations":"GITLAB_TOKEN missing from .env or the deployment's secret store; env var exported as empty string (GITLAB_TOKEN= with no value); config loading silently defaulting to ''; migrating from another adapter and forgetting the GitLab credentials.","solutions":["Set the GitLab token env/config value before constructing the adapter (a personal access or project token with api scope).","Verify the variable is non-empty at startup: print its length, not its value (never log the secret).","Check the .env file is actually loaded in the deployment (env var restored by .env loading can mask deletion — pass '' explicitly to Bun children to suppress).","Fix the config loader so it fails on missing required credentials rather than defaulting to empty strings."],"exampleFix":"// before\nconst adapter = new GitLabAdapter(process.env.GITLAB_TOKEN ?? \"\", secret, locker);\n\n// after\nconst token = process.env.GITLAB_TOKEN;\nif (!token) throw new Error(\"GITLAB_TOKEN is required\");\nconst adapter = new GitLabAdapter(token, secret, locker);","handlingStrategy":"validation","validationCode":"const token = process.env.GITLAB_TOKEN;\nif (typeof token !== 'string' || token.length === 0) {\n  throw new Error('GITLAB_TOKEN must be set to a non-empty value before creating GitLabAdapter');\n}","typeGuard":"function hasGitLabToken(v: unknown): v is string {\n  return typeof v === 'string' && v.length > 0;\n}","tryCatchPattern":"let adapter: GitLabAdapter;\ntry {\n  adapter = new GitLabAdapter(token, webhookSecret, locker);\n} catch (err) {\n  if (err instanceof Error && err.message.includes('non-empty token')) {\n    throw new Error('Startup misconfiguration: GITLAB_TOKEN is missing or empty', { cause: err });\n  }\n  throw err;\n}","preventionTips":["Fail fast at process startup on missing required env vars (check length, never log the value).","Keep credentials in a secret manager rather than loose .env files.","Beware `VAR ?? ''` defaults that convert a missing var into the empty string this error detects.","For Bun children, pass env keys as '' (not delete) to suppress inherited values predictably."],"tags":["gitlab","constructor","config-validation","missing-token"],"backgroundTag":"missing-env-var","analyzedSha":"0773b9745896ef0612e709c80845a0f7db315b19","analyzedAt":"2026-09-01T02:28:07.064Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}