in server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/fsWrite.ts [55:97]
public async validate(params: FsWriteParams): Promise<void> {
if (!params.path) {
throw new Error('Path must not be empty')
}
const sanitizedPath = sanitize(params.path)
switch (params.command) {
case 'create': {
if (params.fileText === undefined) {
throw new Error('fileText must be provided for create command')
}
const fileExists = await this.workspace.fs.exists(sanitizedPath)
if (fileExists) {
const oldContent = await this.workspace.fs.readFile(sanitizedPath)
if (oldContent === params.fileText) {
throw new Error('The file already exists with the same content')
}
}
break
}
case 'strReplace': {
if (params.oldStr === params.newStr) {
throw new Error('The provided oldStr and newStr are the exact same, this is a no-op')
}
const fileExists = await this.workspace.fs.exists(sanitizedPath)
if (!fileExists) {
throw new Error('The provided path must exist in order to replace contents into it')
}
break
}
case 'insert': {
const fileExists = await this.workspace.fs.exists(sanitizedPath)
if (!fileExists) {
throw new Error('The provided path must exist in order to insert contents into it')
}
break
}
case 'append':
if (!params.newStr) {
throw new Error('Content to append must not be empty')
}
break
}
}