(trimmed: string, lineNumber: number)
| 115 | } |
| 116 | |
| 117 | function parseReplayEnvLine(trimmed: string, lineNumber: number): { key: string; value: string } { |
| 118 | const body = trimmed.slice(3).replace(/^[\s]+/, ''); |
| 119 | const eqIndex = body.indexOf('='); |
| 120 | if (eqIndex <= 0) { |
| 121 | throw new AppError( |
| 122 | 'INVALID_ARGS', |
| 123 | `Invalid env directive on line ${lineNumber}: expected "env KEY=VALUE".`, |
| 124 | ); |
| 125 | } |
| 126 | const key = body.slice(0, eqIndex); |
| 127 | if (!REPLAY_VAR_KEY_RE.test(key)) { |
| 128 | throw new AppError( |
| 129 | 'INVALID_ARGS', |
| 130 | `Invalid env key "${key}" on line ${lineNumber}: keys must be uppercase letters, digits, and underscores (e.g. APP_ID).`, |
| 131 | ); |
| 132 | } |
| 133 | if (key.startsWith('AD_')) { |
| 134 | throw new AppError( |
| 135 | 'INVALID_ARGS', |
| 136 | `Invalid env key "${key}" on line ${lineNumber}: the AD_* namespace is reserved for built-in variables. Rename ${key} to avoid the AD_ prefix.`, |
| 137 | ); |
| 138 | } |
| 139 | const rawValue = body.slice(eqIndex + 1); |
| 140 | const value = decodeReplayEnvValue(rawValue, lineNumber); |
| 141 | return { key, value }; |
| 142 | } |
| 143 | |
| 144 | function decodeReplayEnvValue(raw: string, lineNumber: number): string { |
| 145 | if (raw.length === 0) return ''; |
no test coverage detected
searching dependent graphs…