Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Avoid exception when symlink can't be resolved
  • Loading branch information
fluiddot committed Sep 26, 2024
commit a44dad4737ff89fcffb45e99dba87e554bcc19a6
13 changes: 12 additions & 1 deletion src/lib/symlink-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import path from 'path';
import { createNodeFsMountHandler } from '@php-wasm/node';
import { PHP, UnmountFunction } from '@php-wasm/universal';
import { pathExists } from './fs-utils';
import { isErrnoException } from './is-errno-exception';

type MountedTarget = {
preExisting: boolean;
Expand Down Expand Up @@ -137,7 +138,17 @@ export class SymlinkManager {
*/
private async addSymlink( filename: string ) {
const fullPath = path.join( this.projectPath, filename );
const target = await fs.realpath( fullPath );
let target: string;
try {
target = await fs.realpath( fullPath );
} catch ( err ) {
if ( isErrnoException( err ) && err.code === 'ENOENT' ) {
console.error( `Symlink target does not exist: ${ fullPath }` );
return;
}
console.error( err );
return;
}

if ( ! this.php.requestHandler ) {
throw new Error( 'Request handler is not set' );
Expand Down