phalcon/cphalcon · error · Phalcon\Assets\Exceptions\AssetSourceTargetCollision
Asset '{path}' has the same source and target paths
Error message
Asset '{path}' has the same source and target paths What it means
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.
Source
Thrown at phalcon/Assets/Manager.zep:521
/**
* Get the target path, we need to write the filtered content to
* a file
*/
let targetPath = asset->getRealTargetPath(completeTargetPath);
/**
* We need a valid final target path
*/
if (true === empty(targetPath)) {
throw new InvalidAssetTargetPath(asset->getPath());
}
if (true === asset->isLocal()) {
/**
* Make sure the target path is not the same source path
*/
if (targetPath === sourcePath) {
throw new AssetSourceTargetCollision(targetPath);
}
if (true === this->phpFileExists(targetPath)) {
if (filemtime(targetPath) !== filemtime(sourcePath)) {
let filterNeeded = true;
}
} else {
let filterNeeded = true;
}
}
} else {
/**
* If there are no filters, just print/buffer the HTML
*/
let prefixedPath = this->calculatePrefixedPath(
collection,
asset->getRealTargetUri(),
asset->getRealSourcePath()View on GitHub (pinned to b7419de9cd)
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
Example fix
// before
$collection->addCss('css/app.css')->setTargetPath('css/app.css');
// after
$collection->addCss('css/app.css')->setTargetPath('css/app.min.css'); Defensive patterns
Strategy: validation
Validate before calling
$source = rtrim($sourceBasePath, '/') . '/' . ltrim($asset->getPath(), '/');
$target = rtrim($targetBasePath, '/') . '/' . ltrim($asset->getTargetPath(), '/');
if ($source === $target) {
throw new RuntimeException('Asset target would overwrite its own source: ' . $target);
}
echo $assets->outputCss($name); Try / catch
try {
echo $assets->outputCss('app');
} catch (\Phalcon\Assets\Exceptions\AssetSourceTargetCollision $e) {
$logger->error('Refusing to overwrite asset source; set a distinct targetPath: ' . $e->getMessage());
throw $e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Attempting 'minify in place' during deployment; sourceBasePath and targetBasePath both pointing at public/ with identical relative paths; copy-pasted targetPath values.
Related errors
- Path '{path}' is not a valid target path
- Path '{path}' is not a valid target path, it is a directory.
- Asset '{path}' does not have a valid target path
- Asset's content for '{path}' cannot be read
- The collection '{name}' does not exist in the manager
AI-assisted analysis of phalcon/cphalcon@b7419de9cd (2026-08-21).
Data as JSON: /api/errors/30989cd3a4d60e0c.
Report an issue: GitHub.