(path: string)
| 204 | } |
| 205 | |
| 206 | function parseSettingsFileUncached(path: string): { |
| 207 | settings: SettingsJson | null |
| 208 | errors: ValidationError[] |
| 209 | } { |
| 210 | try { |
| 211 | const { resolvedPath } = safeResolvePath(getFsImplementation(), path) |
| 212 | const content = readFileSync(resolvedPath) |
| 213 | |
| 214 | if (content.trim() === '') { |
| 215 | return { settings: {}, errors: [] } |
| 216 | } |
| 217 | |
| 218 | const data = safeParseJSON(content, false) |
| 219 | |
| 220 | // Filter invalid permission rules before schema validation so one bad |
| 221 | // rule doesn't cause the entire settings file to be rejected. |
| 222 | const ruleWarnings = filterInvalidPermissionRules(data, path) |
| 223 | |
| 224 | const result = SettingsSchema().safeParse(data) |
| 225 | |
| 226 | if (!result.success) { |
| 227 | const errors = formatZodError(result.error, path) |
| 228 | return { settings: null, errors: [...ruleWarnings, ...errors] } |
| 229 | } |
| 230 | |
| 231 | return { settings: result.data, errors: ruleWarnings } |
| 232 | } catch (error) { |
| 233 | handleFileSystemError(error, path) |
| 234 | return { settings: null, errors: [] } |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | /** |
| 239 | * Get the absolute path to the associated file root for a given settings source |
no test coverage detected