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

Check for process existence before accessing it #147

Merged
merged 3 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/pinecone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export class Pinecone {
* @returns A {@link PineconeConfiguration} object populated with values found in environment variables.
*/
_readEnvironmentConfig(): PineconeConfiguration {
if (!process || !process.env) {
if (typeof process === 'undefined' || !process || !process.env) {
throw new PineconeEnvironmentVarsNotSupportedError(
'Your execution environment does not support reading environment variables from process.env, so a configuration object is required when calling new Pinecone()'
);
Expand Down
7 changes: 6 additions & 1 deletion src/utils/debugLog.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
export const debugLog = (str: string) => {
if (process && process.env && process.env.PINECONE_DEBUG) {
if (
typeof process !== 'undefined' &&
process &&
process.env &&
process.env.PINECONE_DEBUG
) {
console.log(str);
}
};
14 changes: 12 additions & 2 deletions src/utils/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ const chalk = (str, color) => {
*
* Api-Key headers will be redacted.
*/
if (process && process.env && process.env.PINECONE_DEBUG) {
if (
typeof process !== 'undefined' &&
process &&
process.env &&
process.env.PINECONE_DEBUG
) {
const debugLogMiddleware = {
pre: async (context) => {
console.debug(
Expand Down Expand Up @@ -54,7 +59,12 @@ if (process && process.env && process.env.PINECONE_DEBUG) {
* curl commands for each request. These commands will include the API key and
* other sensitive information, so be careful when using this option.
*/
if (process && process.env && process.env.PINECONE_DEBUG_CURL) {
if (
typeof process !== 'undefined' &&
process &&
process.env &&
process.env.PINECONE_DEBUG_CURL
) {
const debugCurlMiddleware = {
post: async (context) => {
let headers = `-H "Api-Key: ${(context.init.headers || {})['Api-Key']}"`;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/user-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const buildUserAgent = (isLegacy: boolean) => {
}

// If available, capture information about the Node.js version
if (process && process.version) {
if (typeof process !== 'undefined' && process && process.version) {
userAgentParts.push(`node ${process.version}`);
}

Expand Down
1 change: 1 addition & 0 deletions src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ export const buildValidator = (errorMessagePrefix: string, schema: any) => {
}

if (
typeof process !== 'undefined' &&
process &&
process.env &&
process.env.PINECONE_DISABLE_RUNTIME_VALIDATIONS
Expand Down
Loading