Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

# Fix TypeError in process.chdir() call #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

piperTang
Copy link

Fix TypeError in process.chdir() call

Description of the bug

When running the Messari Subgraph CLI, users may encounter the following error:

TypeError: The "directory" argument must be of type string. Received undefined
    at wrappedChdir (node:internal/bootstrap/switches/does_own_process_state:129:3)
    at process.chdir (node:internal/worker:110:5)
    at Object.<anonymous> (C:\Users\Administrator\AppData\Roaming\fnm\node-versions\v20.16.0\installation\node_modules\messari-subgraph-cli\bin\env.ts:4:9)
    ...

This error occurs because process.chdir() is being called with an undefined argument, likely due to process.cwd() returning undefined in certain environments or scenarios.

Proposed fix

Add a check before calling process.chdir() to ensure we have a valid directory string:

if (process.cwd()) {
  process.chdir(process.cwd());
} else {
  console.error('Current working directory is undefined');
  process.exit(1);
}

Impact

This fix prevents the CLI from crashing due to an invalid argument type and provides a more informative error message if the current working directory cannot be determined.

Testing

  • Tested the fix in environments where the error was previously occurring
  • Verified that the CLI functions correctly in normal scenarios
  • Simulated scenarios where process.cwd() might return undefined to ensure proper error handling

Additional notes

  • This issue may be more prevalent in certain environments or file system configurations
  • Consider adding more robust directory handling throughout the CLI to prevent similar issues in the future

Closes #[Issue Number] (if applicable)

When running the Messari Subgraph CLI, users may encounter the following error:
```
TypeError: The "directory" argument must be of type string. Received undefined
    at wrappedChdir (node:internal/bootstrap/switches/does_own_process_state:129:3)
    at process.chdir (node:internal/worker:110:5)
    at Object.<anonymous> (C:\Users\Administrator\AppData\Roaming\fnm\node-versions\v20.16.0\installation\node_modules\messari-subgraph-cli\bin\env.ts:4:9)
    ...
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant