{"record":{"id":"30989cd3a4d60e0c","repo":"phalcon/cphalcon","slug":"asset-path-has-the-same-source-and-target-path","errorCode":null,"errorMessage":"Asset '{path}' has the same source and target paths","messagePattern":"Asset '(.+?)' has the same source and target paths","errorType":"exception","errorClass":"Phalcon\\Assets\\Exceptions\\AssetSourceTargetCollision","httpStatus":null,"severity":"error","filePath":"phalcon/Assets/Manager.zep","lineNumber":521,"sourceCode":"                /**\n                 * Get the target path, we need to write the filtered content to\n                 * a file\n                 */\n                let targetPath = asset->getRealTargetPath(completeTargetPath);\n\n                /**\n                 * We need a valid final target path\n                 */\n                if (true === empty(targetPath)) {\n                    throw new InvalidAssetTargetPath(asset->getPath());\n                }\n\n                if (true === asset->isLocal()) {\n                    /**\n                     * Make sure the target path is not the same source path\n                     */\n                    if (targetPath === sourcePath) {\n                        throw new AssetSourceTargetCollision(targetPath);\n                    }\n\n                    if (true === this->phpFileExists(targetPath)) {\n                        if (filemtime(targetPath) !== filemtime(sourcePath)) {\n                            let filterNeeded = true;\n                        }\n                    } else {\n                        let filterNeeded = true;\n                    }\n                }\n            } else {\n                /**\n                 * If there are no filters, just print/buffer the HTML\n                 */\n                let prefixedPath = this->calculatePrefixedPath(\n                    collection,\n                    asset->getRealTargetUri(),\n                    asset->getRealSourcePath()","sourceCodeStart":503,"sourceCodeEnd":539,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Assets/Manager.zep#L503-L539","documentation":"For a filtered local asset the manager refuses to operate when the resolved target path equals the source path. Writing the filtered result would overwrite the original file with its own minified copy (irreversible data loss), so AssetSourceTargetCollision is thrown as a safety stop.","triggerScenarios":"An asset or collection whose targetPath resolves to exactly the same file as its source, e.g. source 'css/app.css' and target 'css/app.css' (or same base paths), with filters enabled and the asset local.","commonSituations":"Attempting 'minify in place' during deployment; sourceBasePath and targetBasePath both pointing at public/ with identical relative paths; copy-pasted targetPath values.","solutions":["Choose a distinct output filename: `$asset->setTargetPath('css/app.min.css')` (or a separate targetBasePath such as public/build/)","If you truly want in-place replacement, minify outside Phalcon in a build step that works on a copy","Keep generated artifacts out of source directories so this collision cannot occur"],"exampleFix":"// before\n$collection->addCss('css/app.css')->setTargetPath('css/app.css');\n// after\n$collection->addCss('css/app.css')->setTargetPath('css/app.min.css');","handlingStrategy":"validation","validationCode":"$source = rtrim($sourceBasePath, '/') . '/' . ltrim($asset->getPath(), '/');\n$target = rtrim($targetBasePath, '/') . '/' . ltrim($asset->getTargetPath(), '/');\nif ($source === $target) {\n    throw new RuntimeException('Asset target would overwrite its own source: ' . $target);\n}\necho $assets->outputCss($name);","typeGuard":null,"tryCatchPattern":"try {\n    echo $assets->outputCss('app');\n} catch (\\Phalcon\\Assets\\Exceptions\\AssetSourceTargetCollision $e) {\n    $logger->error('Refusing to overwrite asset source; set a distinct targetPath: ' . $e->getMessage());\n    throw $e;\n}","preventionTips":["Write build output to a separate directory (e.g. public/build/) or a .min. filename suffix","Never configure identical sourceBasePath+path and targetBasePath+targetPath for filtered assets","Treat this exception as a data-loss guard — do not silence it"],"tags":["assets","target-path","data-loss","safety-check"],"backgroundTag":"source-target-path-collision","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}