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